#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
using namespace std;
const int n = 2;
const int mod = 10000;
int a[3][3], e[3][3], ans[3][3];
struct Matrix{
int a[n+1][n+1];
Matrix(int t[3][3])
{
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
a[i][j] = t[i][j];
}
Matrix& operator *= (const Matrix& a2);
};
Matrix&
Matrix::operator *= (const Matrix& m2){
int tempp[n+1][n+1];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
{
int temp = 0;
for(int k = 1; k <= n; k++)
{
temp += a[i][k] * m2.a[k][j];
temp %= mod;
}
tempp[i][j]= temp;
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
a[i][j] = tempp[i][j];
return *this;
}
Matrix
quick_multiply(int N){
Matrix res(a);
Matrix ans(e);
while(N){
if(N&1){
ans *= res;
}
res *= res;
N = N>>1;
}
return ans;
}
int main(){
memset(a, 0, sizeof(a));
memset(e, 0, sizeof(e));
memset(ans, 0, sizeof(ans));
a[1][1] = 1; a[2][1] = 1; a[1][2] = 1;
e[1][1] = 1; e[2][2] = 1;
int N;
while(scanf("%d", &N) && N != -1){
if(N == 0){
printf("0\n");
continue;
}
if(N == 1){
printf("1\n");
continue;
}
Matrix ans = quick_multiply(N-1);
int last = ans.a[1][1]%mod;
printf("%d\n",last);
}
return 0;
}