#include <bits/stdc++.h>
using namespace std;
int const maxn = (int)1e5 + 111;
int const inf = (1 << 30) - 1;
int n, m, ans, cnt;
string second;
int main() {
  cin >> second;
  cin >> n;
  if (second == "0") {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < second.size(); ++i) {
    if (second[i] == '0') {
      ++m;
    }
  }
  if (m < n) {
    cout << second.size() - 1 << endl;
    return 0;
  }
  for (int i = second.size() - 1; i >= 0; --i) {
    if (second[i] != '0') {
      --m;
      ++ans;
    } else {
      ++cnt;
    }
    if (cnt == n) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
