#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
cin >> n;
int a = 0;
int b = 1;
int c = 0;
for (int i = 1; c <= n; i++)
{
c = a + b;//13 21
a = b; //8 13
b = c; //13 21
}
a = abs(a - n);//2
b = abs(b - n);//6
int minn = min(a, b);
cout << minn << endl;
return 0;
}