#include <bits/stdc++.h>
using namespace std;
int n;
int a[200], b[200], num[100], numa[100];
int main() {
  if (fopen("H://poiuyzxcvb029.txt", "r") != NULL) {
    freopen("H://poiuyzxcvb029.txt", "r", stdin);
  }
  char s[1000];
  while (scanf("%s %d", s, &n) != EOF) {
    int len = strlen(s);
    int sum = 0, del = 0;
    for (int i = len - 1; i >= 1; i--) {
      if (s[i] == '0') {
        sum++;
      } else {
        del++;
      }
      if (sum >= n) {
        break;
      }
    }
    if (sum >= n) {
      printf("%d\n", del);
    } else {
      printf("%d\n", len - 1);
    }
  }
  return 0;
}
