#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > xy;
vector<pair<long long, long long> > ab;
vector<long long> x;
vector<long long> y;
string str, str1, str2, star[2000];
long long ara[200005], ara2[200005];
bool flagar[200005], flagar2[200005];
bool compare(pair<long long, long long> i, pair<long long, long long> j) {
  return (i.first < j.first);
}
bool compare2(pair<long long, long long> i, pair<long long, long long> j) {
  return (i.first > j.first);
}
long long gcd(long long a, long long b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long dp[2005][2005];
int main() {
  long long int n, ans, temp, t, j, i, m, h, h2, m2, c, a, b, mx, d, k, x1, r,
      l, mn;
  cin >> str >> k;
  n = str.length();
  a = b = 0;
  for (i = n - 1; i >= 0; i--) {
    if (str[i] - '0' == 0)
      a++;
    else
      b++;
    if (a == k) {
      cout << b;
      return 0;
    }
  }
  if (a < k) {
    b = n - 1;
  }
  cout << b;
  return 0;
}
