en an array of n integers, find the maximum element in the given array. Note : Do not use any inbuilt functions that find the maximum element directly. Input format There are two lines of input First line contains the integer n. Next line contains n space separated integers. Output format Print the maximum element in the array. Sample Input 1 5 1 2 3 1 2 Sample Output 1 3 Explanation 1 3 is the maximum value in the array. Constraints 1 <= n <= 10000 1 <= element of array <= 100000


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.replace(/\s+/g, " ").trim();
    });
    main();
});

function readLine() {
    return inputString[currentLine++];
}

function readIntArr() {
    let str = readLine();
    str = str.split(" ");
    let arr = [];
    for (let i = 0; i < str.length; i++) {
        arr.push(parseInt(str[i], 10));
    }
    return arr;
}

function print(x) {
    process.stdout.write(x + "");
}


/**
 * @param {number} n
 * @param {number[]} arr
 * @return {number}
 */


// TODO: Implement this method
function maxInArray(n, arr) {
    for(let i=0; i<n; i++){
        if(arr[i] > arr[i+1]){
            return arr[i];
        }
    }
}
// NOTE: Please do not modify this function
function main() {
    let n = parseInt(readLine(), 10);
    let arr = readIntArr();
    let result = maxInArray(n, arr);
    console.log(result);
}

/* 
  Crio Methodology
  
  Milestone 1: Understand the problem clearly
  1. Ask questions & clarify the problem statement clearly.
  2. *Type down* an example or two to confirm your understanding of the input/output & extend it to test cases
  
  Milestone 2: Finalize approach & execution plan
  1. Understand what type of problem you are solving.
       a. Obvious logic, tests ability to convert logic to code
       b. Figuring out logic
       c. Knowledge of specific domain or concepts
       d. Knowledge of specific algorithm
       e. Mapping real world into abstract concepts/data structures
  2. Brainstorm multiple ways to solve the problem and pick one
  3. Get to a point where you can explain your approach to a 10 year old
  4. Take a stab at the high-level logic & *type it down*.
  5. Try to offload processing to functions & keeping your main code small.
  
  Milestone 3: Code by expanding your pseudocode
  1. Have frequent runs of your code, dont wait for the end
  2. Make sure you name the variables, functions clearly.
  3. Avoid constants in your code unless necessary; go for generic functions, you can use examples for your thinking though.
  4. Use libraries as much as possible
  
  Milestone 4: Prove to the interviewer that your code works with unit tests
  1. Make sure you check boundary conditions
  2. Time & storage complexity
  3. Suggest optimizations if applicable
  */