#!/usr/bin/env python # -*- coding: utf-8 -*- N = int(input()) MM = [int(input()) for i in range(0,N)] dp = [10**9 for i in range(1<