import java.io.*;
import hsa.Console;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.lang.Math;

// The "Template" class.
public class FILE_TEMP
{
    static FileReader inFile;
    static FileWriter outFile;

    // Link the input and output file for
    static BufferedReader in;
    static BufferedWriter out;


    public static void main (String[] args) throws IOException
    {

	// Open up the input and output file for IO purpose

	inFile = new FileReader ("DATA2.txt");
	outFile = new FileWriter ("OUT2.txt");

	// Link the input and output file for
	in = new BufferedReader (inFile);
	out = new BufferedWriter (outFile);
	String line;
	int difference1 = 1000000001;
	int difference2;

	int[] Fibonacci = new int [47];
	int count = 0;
	
	int found= 0;

	// generate Fibonacci
	Fibonacci [0] = 0;
	Fibonacci [1] = 1;
	for (count = 2 ; count < 47 ; count++)
	{
	    Fibonacci [count] = Fibonacci [count - 1] + Fibonacci [count - 2];
	    //check
	    //System.out.println (Fibonacci[count]);
	}
	int targetNumber;

	// Keep reading as long as not end of file (eof)
	while ((line = in.readLine ()) != null)
	{
	    targetNumber = Integer.parseInt (line);
	    for (count = 0 ; count < 47 ; count++)
	    {
	       difference2 = targetNumber - Fibonacci[count];
	       if (difference2 < 0)
	       {
	       difference2 = Fibonacci[count] - targetNumber;
	       //System.out.println (difference2);
	       }
	       if (difference2 == difference1)
	       {
	       found = count;
	       }
	       else if (difference2 < difference1)
	       {
	       found = count;
	       //System.out.println(""+ found);
	       difference1 = difference2;
	       }
	      
	    }
	    out.write("" +Fibonacci[found]);
	    out.newLine();
	    found = 0;
	    difference2 = 0;
	    difference1 = 1000000001;
	}
	out.flush ();
	out.close ();
    }
} // main method
// End of Class



