#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main() {
string n;
cin >> n;
int f = (n[0] - '0');
int s = (n[1] - '0');
int t = (n[2] - '0');
for(int i = 0; i < 1000; i++) {
int tmp = t;
t = (t + s + f) % 10;
n += (t + '0');
int sz = (int) n.size();
if(n[0] == n[sz - 3] and n[1] == n[sz - 2] and n[2] == n[sz - 1]) {
n.erase(n.end() - 1);
n.erase(n.end() - 1);
n.erase(n.end() - 1);
break;
}
f = s;
s = tmp;
}
long long K;
cin >> K;
int sz = (int) n.size();
long long pos = K % sz;
if(pos == 0) {
cout << n[sz - 1] << endl;
}
else {
cout << n[pos - 1] << endl;
}
return 0;
}