"""
Find the most frequent integer in an array.
"""
from collections import Counter


def most_frequent(arr):
    counter = Counter(arr)
    max_freq = 0
    max_key = None
    for key, frequency in counter.iteritems():
        if max_freq < frequency:
            max_freq = frequency
            max_key = key
    return max_key


if __name__ == '__main__':
    print most_frequent([2, 1, 2, 3, 4, 2, 1])