#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;
string fun(string s , int n) {
if (s.size() == 1 && n == 1) {
return s;
}
long long sm = 0;
for (int i = 0; i < s.size(); i++) {
sm += s[i] - '0';
}
sm *= n;
return fun(to_string(sm) , 1);
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
string s;
int n;
cin >> s >> n;
cout << fun(s , n);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8cXVldWU+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnN0cmluZyAgZnVuKHN0cmluZyBzICwgaW50IG4pIHsKICAgIGlmIChzLnNpemUoKSA9PSAxICYmIG4gPT0gMSkgewogICAgICAgIHJldHVybiBzOwogICAgfQogICAgICBsb25nIGxvbmcgc20gPSAwOwogICAgICBmb3IgKGludCBpID0gMDsgaSA8IHMuc2l6ZSgpOyBpKyspIHsKICAgICAgICAgIHNtICs9IHNbaV0gLSAnMCc7CiAgICAgIH0KICAgICAgc20gKj0gbjsKICAgICAgcmV0dXJuIGZ1bih0b19zdHJpbmcoc20pICwgMSk7Cn0KaW50IG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7ICAgIGNpbi50aWUoTlVMTCk7ICAgICBjb3V0LnRpZShOVUxMKTsKICAgIHN0cmluZyBzOwogICAgaW50IG47CiAgICBjaW4gPj4gcyA+PiBuOwogICAgY291dCA8PCBmdW4ocyAsIG4pOwoKfQo=