#include<bits/stdc++.h>
using namespace std;

inline int read()
{
	int w=1,x=0;char f=getchar();
	while(!isdigit(f) && f!='-') f=getchar();
	if(f=='-') {w=-1;f=getchar();}
	while(isdigit(f)) {x=(x<<3)+(x<<1)+f-48;f=getchar();}
	return w*x;
}

int a,b,ans;
int main()
{
	a=read();b=read();
	ans=2*a+100-b;
	printf("%d\n",ans);
	return 0;
}
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        map<ll,set<ll>> s;
        vector<ll> a(n), b(n);
        for(i = 0; i < n; i++){
            cin >> a[i];
            s[a[i] + i].insert(i);
        }        
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        indexed_set st;
        ll ans = 0;
        for(i = 0; i < n; i++){
            ll sum = b[i] + i;
            if(s[sum].empty()){
                cout << -1 << endl;
                return 0;
            }
            ll pos = *s[sum].begin();
            ll posi = st.order_of_key(pos);
            ans += pos - posi;
            s[sum].erase(s[sum].begin());
            st.insert(pos);
        }
        cout << ans << endl;
    }
    return 0;
}