#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define NAME "tenbai"
using namespace std;
// Your large MOD
const int MOD = 123456789987654321;
// Define a 2x2 Matrix structure
struct Matrix {
int mat[2][2];
Matrix() {
mat[0][0] = mat[0][1] = mat[1][0] = mat[1][1] = 0;
}
};
// Function to multiply two matrices
Matrix multiply(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
// CRITICAL: Use __int128_t to prevent overflow during multiplication
// because MOD * MOD exceeds long long range.
__int128_t val = (__int128_t)A.mat[i][k] * B.mat[k][j];
C.mat[i][j] = (C.mat[i][j] + (int)(val % MOD)) % MOD;
}
}
}
return C;
}
// Function to calculate A^p using Binary Exponentiation (Exponentiation by Squaring)
Matrix power(Matrix A, int p) {
Matrix res;
// Identity matrix
res.mat[0][0] = 1; res.mat[0][1] = 0;
res.mat[1][0] = 0; res.mat[1][1] = 1;
A.mat[0][0] %= MOD;
A.mat[0][1] %= MOD;
A.mat[1][0] %= MOD;
A.mat[1][1] %= MOD;
while (p > 0) {
if (p & 1) res = multiply(res, A);
A = multiply(A, A);
p >>= 1;
}
return res;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
int n;
if (!(cin >> n)) return 0;
// Handle base cases manually
if (n == 0) {
cout << 0 << endl;
return 0;
}
if (n == 1) {
cout << 1 << endl;
return 0;
}
// Base Matrix:
// [1 1]
// [1 0]
Matrix T;
T.mat[0][0] = 1; T.mat[0][1] = 1;
T.mat[1][0] = 1; T.mat[1][1] = 0;
// We need T^(n-1) to get the nth term
T = power(T, n - 1);
// The result is roughly F(n) = T.mat[0][0] * F(1) + T.mat[0][1] * F(0)
// Since F(1)=1, F(0)=0, the answer is just T.mat[0][0]
cout << T.mat[0][0] << endl;
return 0;
}