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