#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k, n, cz = 0, ct = 0;
  scanf("%d", &k);
  n = s.length();
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '0') {
      cz++;
    } else {
      ct++;
    }
    if (cz == k) {
      printf("%d", ct);
      return 0;
    }
  }
  if (cz < k) {
    printf("%d", n - 1);
  }
  return 0;
}
