#!/bin/python import sys def longestSequence(a): # Return the length of the longest possible sequence of moves. queue = [a] step = 0 while len(queue) > 0: size = len(queue) for _ in range(size): a = queue.pop(0) if a[0] == 1: a.pop(0) if len(a) > 0: queue.append(a) else: for piece in range(a[0] - 1, 0, - 1): curr = a[1:] if a[0] % piece == 0: for _ in range(a[0] / piece): curr.append(piece) queue.append(curr) step += 1 return step if __name__ == "__main__": n = int(raw_input().strip()) a = map(long, raw_input().strip().split(' ')) result = longestSequence(a) print result