process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function main() { var n = parseInt(readLine()); types = readLine().split(' '); types = types.map(Number); // your code goes here var pairs = new Map(); types.forEach(function(element) { if (pairs.has(element)) { pairs.set(element, pairs.get(element) + 1); } else { pairs.set(element, 1); } }); var max; pairs.forEach(function(value, key) { if (max == undefined) { max = [key, value]; } if (max[1] < value) { max = [key, value]; } else if ((max[1] === value) && (max[0] > key)) { max = [key, value]; } }); console.log(max[0]); }