#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
using ll = long long int;

const ll INF = 1LL << 60;
ll N;
string s;

void chmin(ll &A, ll B) {
  A = min(A, B);
}

ll dp[1010][1010][12][2];
int main() {
  cin >> N >> s;
  reverse(s.begin(), s.end());
  int L = s.length();

  fill(dp[0][0][0], dp[L+1][0][0], INF);
  dp[0][0][0][0] = 0;

  string pat = "0123456789+";
  
  ll pow_tab[12] = {};
  pow_tab[0] = 1;
  for(int i=1; i<12; i++) {
    pow_tab[i] = pow_tab[i-1] * 10;
  }

  for(int i=0; i<L; i++) {
    for(int j=0; j<=i; j++) {
      for(int k=0; k<=10; k++) {
	for(int f=0; f<2; f++) {
	  if(dp[i][j][k][f] == INF) continue;
	  for(auto c : pat) {
	    int cost = (c != s[i]);
	    if(c == '+') {
	      bool ng = false;
	      // previous char
	      ng |= (k == 0);

	      // leading zero
	      ng |= (f == 1 and k >= 2);

	      if(ng == false) {
		int nk = 0, nf = 0;
		chmin(dp[i+1][j+cost][nk][nf], dp[i][j][k][f]);
	      }
	    }
	    else { // digit
	      ll add = pow_tab[k] * (c - '0');
	      chmin(dp[i+1][j+cost][k+1][c == '0'], dp[i][j][k][f] + add);
	    }
	  }
	}
      }
    }
  }

  /*
  for(int i=0; i<=L; i++) {
    for(int j=0; j<=i; j++) {
      for(int k=0; k<=10; k++) {
	for(int f=0; f<2; f++) {
	  if(dp[i][j][k][f] == INF) continue;
	  fprintf(stderr, "dp[%d][%d][%d][%d] = %lld\n", i, j, k, f, dp[i][j][k][f]);
	}
      }
    }
  }
  */

  const int NONE = L + 10;
  int ans = NONE;
  for(int j=0; j<=L; j++) {
    for(int k=0; k<=10; k++) {
      for(int f=0; f<2; f++) {
	bool ng = false;
	// previous char
	ng |= (k == 0);
	
	// leading zero
	ng |= (f == 1 and k >= 2);
	
	if(ng == false and dp[L][j][k][f] <= N) {
	  ans = min(ans, j);
	}
      }
    }
  }
  cout << (ans == NONE ? -1 : ans) << endl;
  return 0;
}

