#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int n, i, j, k, t, m;
int c;
string s;
int main() {
  cin >> s >> n;
  reverse(s.begin(), s.end());
  for (c = i = 0; i < s.size() && n > 0; i++) {
    if (s[i] == '0')
      n--;
    else
      c++;
  }
  if (n > 0) c = s.size() - 1;
  printf("%d\n", c);
  return 0;
}
