#include<iostream>
using namespace std;
int main()
{
    int n, a,b;
    cin>>n>>a>>b;
    int i=2, p, x;
    while(i<n)
    {
        x=a*b;
        int y=1, t=0;
        while(x>0)
        {
            int z;
            if(x%10==0)z=9;
            else z=x%10-1;
            t+=z*y;
            x=x/10;
            y=y*10;
        }
        p=t%1000;
        a=b;
        b=p;
        i++;
    }
    cout<<p<<endl;

    return 0;
}
// 3908
