#include using namespace std; vector c = {6, 2, 5, 5, 4, 5, 6, 4, 7, 6}; string f(string S){ if (S[0] == '-'){ return to_string(1 + stoi(f(S.substr(1)))); } int N = S.size(); int ans = 0; for (int i = 0; i < N; i++){ ans += c[S[i] - '0']; } return to_string(ans); } int main(){ string P; cin >> P; string N; cin >> N; if (N.size() < 2){ int N2 = stoi(N); for (int i = 0; i < N2; i++){ P = f(P); } cout << P << endl; } else { map mp; mp[P] = 0; int t = 0; int c; while (true){ t++; P = f(P); if (mp.count(P)){ c = t - mp[P]; break; } else { mp[P] = t; } } int L = N.size(); int r = 0; for (int i = 0; i < L; i++){ r = (r * 10 + (N[i] - '0')) % c; } int t2 = t - 1; while (t2 % c != r){ t2--; } for (auto p : mp){ if (p.second == t2){ cout << p.first << endl; } } } }