#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
const int MAXN = 100;
const int MOD = 10000;
struct Matrix
{
vector< vector<int> > a;
int n, m;
Matrix(int n, int m) : n(n), m(m)
{
a.resize(n);
for (int i = 0; i < n; i++) a[i].resize(m);
}
void cpy(const Matrix &B)
{
n = B.n;
m = B.m;
a.resize(n);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
a[i].resize(m);
a[i][j] = B.a[i][j] % MOD;
}
}
void multiply(const Matrix &B)
{
//if (m != B.n) exit(250);
Matrix t(n, B.m);
for (int i = 0; i < n; i++)
for (int j = 0; j < B.m; j++)
for (int k = 0; k < m; k++)
t.a[i][j] = (t.a[i][j] + a[i][k] * B.a[k][j]) % MOD;
cpy(t);
}
void print()
{
for (int i = 0; i < n; i++) {
cout << endl;
for (int j = 0; j < m; j++)
cout << ' ' << a[i][j];
}
}
void eye()
{
for (int i = 0; i < n; i++) a[i][i] = 1;
}
void power(int p)
{
Matrix res(n, m);
res.eye();
Matrix t(n, m);
t.cpy(*this);
while (p)
{
if (p & 1) res.multiply(t);
p >>= 1;
t.multiply(t);
}
cpy(res);
}
};
void solve(int n)
{
Matrix a(2, 1);
a.a[0][0] = 0;
a.a[1][0] = 1;
Matrix b(2, 2);
b.a[0][0] = 1; b.a[0][1] = 1;
b.a[1][0] = 1; b.a[1][1] = 0;
b.power(n);
//b.print();
b.multiply(a);
cout << b.a[0][0] << endl;
}
int main()
{
//freopen("in", "r", stdin);
int n;
for (;;) {
scanf("%d", &n);
if (n == -1) break;
solve(n);
}
}
11-08
11-08
11-08