#include<iostream>
#include<cmath>
using namespace std;
unsigned long long magic(unsigned long long c){
    unsigned long long copie = c, izhod = 0;
    for(unsigned long long i = 0; copie >= 0 && i < 3; i++){
        if(copie % 10 > 0){
            izhod += pow(10, i) * (copie % 10 - 1);
        }else{
            izhod += pow(10, i) * 9;
        }
        copie /= 10;
    }
    return izhod % 1000;
}
int main(){
    unsigned long long n, a, b, c;
    cin >> n >> a >> b;
    for(unsigned long long i = 0; i < n - 2; i++){
        c = a * b;
        c = magic(c);
        a = b;
        b = c;
    }
    cout << c;
    return 0;
}
