#include <bits/stdc++.h>
using namespace std;
;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 6e4 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int k;
string s;
int main() {
  cin >> s >> k;
  int num = 0, ans = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (num >= k) break;
    if (s[i] == '0') {
      num++;
    } else {
      ans++;
    }
  }
  if (num >= k) {
    printf("%d\n", ans);
  } else {
    printf("%d\n", s.size() - 1);
  }
  return 0;
}
