#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
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;
F = S;
S = tmp;
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;
}
}
long long K;
cin >> K;
K %= n.size();
if(K == 0) {
cout << n[n.size() - 1] << endl;
}
else {
cout << n[K - 1] << endl;
}
return 0;
}
//1753531933519559931371191113597