#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k, x = 0;
  cin >> s >> k;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == '0') x++;
  if (x < k) {
    cout << s.length() - 1 << endl;
    return 0;
  }
  x = 0;
  int i = s.length(), ans = 0;
  while (x < k) {
    i--;
    if (s[i] == '0')
      x++;
    else
      ans++;
  }
  cout << ans << endl;
  return 0;
}
