#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = (int)1e6 + 100;
const int M = (int)1e4 + 4;
const int INF = (int)0x3f3f3f3f;
const double ESP = 1e-7;
const long long MOD = 1e8 + 9;
string s;
int k, cnt = 0;
int Solve() {
  cin >> s >> k;
  for (int i = s.length() - 1; i >= 0; --i) {
    if (k <= 0) break;
    if (s[i] == '0') {
      --k;
    } else {
      ++cnt;
    }
  }
  if (k <= 0)
    cout << cnt << endl;
  else
    cout << s.size() - 1 << endl;
  return 0;
}
int main() {
  Solve();
  return 0;
}
