#include <bits/stdc++.h>
using namespace std;
struct QuickIO {
  QuickIO() {
    const int SZ = 1 << 20;
    setvbuf(stdin, new char[SZ], _IOFBF, SZ);
    setvbuf(stdout, new char[SZ], _IOFBF, SZ);
  }
} QIO;
template <class T>
void PrintArray(T* first, T* last, char delim = ' ') {
  for (; first != last; first++)
    cout << *first << (first + 1 == last ? '\n' : delim);
}
const int debug = 1;
const int size = 10 + 1000;
const int INF = INT_MAX >> 1;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  char str[size];
  cin >> str >> n;
  int len = strlen(str);
  int cnt = 0;
  for (int i = len; i >= 0; i--) {
    if (str[i] == '0') cnt++;
    if (cnt >= n) {
      cout << len - i - cnt << endl;
      break;
    }
  }
  if (cnt < n) cout << len - 1 << endl;
  return 0;
}
