import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here // 入力 FastScanner sc = new FastScanner(System.in); long[] A = new long[5]; for(int i = 0; i < 5; i++){ A[i] = sc.nextLong(); } // フィボナッチ数列作成 long[] fibo = new long[100]; Arrays.fill(fibo,-1L); fibo[0] = 1L; fibo[1] = 1L; for(int i = 2; i < 100; i++){ fibo[i] = fibo[i-1] + fibo[i-2]; if(fibo[i] > 1000000000000000L){ break; } } // 判定 int count = 0; int startId = -1; long num = A[4]; for(int j = 0; j < 100; j++){ if(num == fibo[j]){ startId = j; count++; break; }else if(num < fibo[j]){ break; } } //System.out.println(startId); if(startId != -1){ int id = startId + 1; for(int i = 3; i >= 0; i--){ //System.out.println("A=" + A[i] + " fibo=" + fibo[id]); if(A[i] == fibo[id]){ count++; id++; }else{ break; } } } if(startId == 0){ startId = 1; int id = startId + 1; int count2 = 1; for(int i = 3; i >= 0; i--){ if(A[i] == fibo[id]){ count2++; id++; }else{ break; } } //System.out.println(count); //System.out.println(count2); if(count < count2){ count = count2; } } // 出力 System.out.println(count); } // 高速スキャナー static class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } }