#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;

using ld=long double;
const ld eps=1e-9;


int main() {
	long long int K;cin>>K;
	string st;cin>>st;
	int N=st.size();
	vector<vector<vector<long long int>>>dp(N+11,
		vector<vector<long long int>>(N+11,vector<long long int>(2,2e9)));
	dp[0][0][0]=0;
	for (int l = 0; l < N; ++l) {
		for (int cnt = 0; cnt < N; ++cnt) {


			for (int type = 0; type < 2; ++type) {
				if (type == 1) {
					if (st[l] == '+') {
						dp[l + 1][cnt][0] = min(dp[l + 1][cnt][0], dp[l][cnt][type]);
					}
					else {
						dp[l + 1][cnt+1][0] = min(dp[l + 1][cnt+1][0], dp[l][cnt][type]);
					}
				}
				else {
					for (int len = 1; len <= min (10,N-l); ++len) {
						string ast = st.substr(l, len);

						int dame_cnt = 0;
						for (int j = 0; j < len; ++j) {
							if (j == 0 && len != 1) {
								if (ast[j] == '0') {
									ast[j] = '1';
									dame_cnt++;
								}
								if (ast[j] == '+') {
									ast[j] = '1';
									dame_cnt++;
								}
							}
							if (ast[j] == '+') {
								ast[j] = '0';
								dame_cnt++;
							}
						}

						int change_cnt = dame_cnt;
						int k=0;
						
						while (true) {
							long long int num=stoll(ast);
							dp[l+len][cnt+change_cnt][1]=
								min(dp[l+len][cnt+change_cnt][1],
									dp[l][cnt][0]+num);

							if(k==len)break;
							while (true) {
								if (k == len)break;
								if (k == 0 && len != 1) {
									if (ast[k] == '1') {
										k++;
									}
									else {
										ast[k]='1';
										k++;
										break;
									}
								}
								else {
									if (ast[k] == '0') {
										k++;
									}
									else {
										ast[k]='0';
										k++;
										break;
									}
								}
							}
							change_cnt++;
						}
					}
				}
			}
		}
	}

	int ans=1e9;
	for (int i = 0; i <= N; ++i) {
		if (dp[N][i][1] <= K) {
			ans=min(ans,i);
		}
	}
	if(ans>100000)ans=-1;
	cout<<ans<<endl;
	return 0;
} 
