#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(5e5)+10;
int n,a[maxn],b[maxn];
ll ans;
char s[maxn],t[maxn];
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	scanf("%s",s+1); scanf("%s",t+1);
	for (int i=1;i<=n;i++) a[i]=s[i]-'0';
	for (int i=1;i<=n;i++) b[i]=t[i]-'0';
	for (int i=1,j=0;i<=n;i++) {
		if (j<=i) j=i+1;
		if (a[i]!=b[i]) {
			while (j<=n&&a[j]==0) j++;
			if (j>n) { puts("-1"); return 0; }
			ans+=j-i; a[j]=0;
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/
#include<bits/stdc++.h>
using namespace std;			
#define ll long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,k,n) for(int i=k;i<=n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define newl "\n"
#define vi vector <int>
#define pii pair <int,int>
#define fi first
#define se second
#define st(x) x.begin()
#define en(x) x.end()
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define len(x) x.length()
#define MAX *max_element
#define MIN *min_element
#define int long long int
const int MOD = 1e9 + 7;

template <typename T>
void print(T &x){
	for (auto &ele : x) cout << ele << ' ';
		cout << "\n";
}


void solveforcase(int tc){

	int n;
	cin>>n;
	int a[n];
	rep(i,n) cin>>a[i];
	int count = 0;
	rep(i,n){
		if(a[i]>=10){
			count += a[i]-10;
		}
	}

	cout << count << "\n";

}

signed main(){
	ios ::sync_with_stdio(0);
    cin.tie(0);

	int T = 1;
	
	for(int tc = 1; tc<=T;tc++){
		solveforcase(tc);
	}
}