import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int count; static long longestSequence(long[] a) { // Return the length of the longest possible sequence of moves. long n = max(a); return n; } static long mergeSort(long l,long r) { if (l < r) { long m = (l+r)/Long.parseLong(2+""); //System.out.println("l = "+l+"m = "+m+"count = "+count); count++; mergeSort(l,m); //System.out.println("m = "+m+"r = "+m+"count = "+count); count++; mergeSort(m+1,r); } if(l==r) { return 0; } return count; } static long max(long a[]) { int i ; long max = 0; for(i = 0;i < a.length; i++) { max += mergeSort(0,a[i]-1); count = 0; } return max; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] a = new long[n]; for(int a_i = 0; a_i < n; a_i++){ a[a_i] = in.nextLong(); } long result = longestSequence(a); System.out.println(result); in.close(); } }