#include using namespace std; using ll = long long int; vector D = {6,2,5,5,4,5,6,4,7,6}; ll f(ll x){ if(x < 0) return 1 + f(-x); if(x < 10) return D[x]; return f(x / 10) + f(x % 10); } int main(){ string P,n; ll N; cin >> P >> n; if(n.size() > 1) N = 6; else N = min(stoi(n),6); if(N == 0){ cout << P << endl; return 0; } ll A = 0; for(ll i = 0;i < P.size();i++){ if(P[i] == '-') A++; else A += D[P[i] - '0']; } N--; for(ll i = 0;i < N;i++) A = f(A); cout << A << endl; }