#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n=5;
    vector<ll> a(n);
    int i;
    for(i=0; i<5; i++) {
        scanf("%lld", &a[4-i]);
    }

    vector<ll> b(100);
    b[0]=1; b[1]=1;
    for(i=2; i<100; i++) {
        b[i]=b[i-1]+b[i-2];
    }

    int max=0;
    int j;
    for(i=0; i<100; i++) {
        for(j=0; j<5; j++) {
            if(a[j]!=b[i+j]) break;
        }
        max=MAX(max,j);
    }
    printf("%d\n", max);

    return 0;
}