#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
if(n <= 15)
cout << n * n;
else if( n >= 16 && n <= 30) {
int s = 0;
while (n > 0) {
s = s + n % 10;
n = n / 10;
}
cout << s;
}
else{
int p = 1;
while (n > 0) {
p = p * n % 10;
n = n / 10;
}
cout << p;
}
return 0;
}