#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#define re register
#define pb push_back
#define cl clear
#define MAXN 100005

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

inline int read(){
	int x = 0, f = 1;
	char ch = getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f = -1;
		ch = getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch = getchar();
	}
	return x*f;
}

ll n, l, A[MAXN], B[MAXN], ans;

void solve(){
    n = read();
    l = read();
    A[n+1] = B[n+1] = l + 1;
    for(re int i = 1 ; i <= n ; ++i)
        A[i] = read();
    for(re int i = 1 ; i <= n ; ++i)
        B[i] = read();
    for(re int i = n + 1 ; i >= 1 ; --i){
        A[i] = A[i] - A[i-1] - 1;
        B[i] = B[i] - B[i-1] - 1;
    }
    int cnt = 1;
    for(re int i = 1 ; i <= n + 1 ; ++i){
        if(!B[i]) continue;
        while(!A[cnt]) ++cnt;
        ll sum = 0, st = cnt, ed;
        while(sum<B[i]&&cnt<=n+1){
            sum += A[cnt++];
            //printf("i = %d cnt = %d sum = %d\n",i,cnt,sum);
        }
        if(sum!=B[i]){
            printf("-1\n");
            return ;
        }
        ed = cnt - 1;
        ans += max(0ll,i-st) + max(0ll,ed-i);
    }
    printf("%lld\n",ans);
}

int main(){
    int t = 1;
    //t = read();
    while(t--) solve();
    return 0;
}

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;

int main(){
    int N,M,tmp,cnt,ANS_size;
    vector<int>vec,ANS_vec;
    cin>>N>>M;
    for(int i = 1;i<=N+M;i++){
        cin>>tmp;
        vec.push_back(tmp);
    }
    for(int i=1;i<=pow(10,3);i++){
        cnt = 0;
        for(int j=0;j<N+M;j++){
            if(vec[j] == i){
                cnt++;
            }
        }
        if(cnt == 1){
            ANS_vec.push_back(i);
        };
    }

    ANS_size = ANS_vec.size();
    for(int i=0;i<ANS_size;i++){
        cout<<ANS_vec[i]<<" ";
    }
    cout<<endl;
}
