#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);

}
