#include <bits/stdc++.h>
using namespace std;
char ch[200020];
int k, ans;
int main() {
  scanf("%s%d", ch + 1, &k);
  int len = strlen(ch + 1);
  int now, cnt = 0, num = 0;
  for (int i = 1; i <= len; i++) {
    if (ch[i] == '0') num++;
  }
  if (num == 1 && len == 1) {
    printf("0\n");
    return 0;
  } else if (num < k && num) {
    printf("%d\n", len - 1);
    return 0;
  }
  for (now = len; now; now--) {
    if (ch[now] == '0')
      cnt++;
    else
      ans++;
    if (cnt >= k) break;
  }
  printf("%d\n", ans);
  return 0;
}
