#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

int main()
{
	ios_base::sync_with_stdio(false);
	
	int n;
	string t;

	string p = "110";
	ll len = 300000LL * 100000LL;

	cin >> n >> t;

	bool ok[3] = { true, true, true };
	for(int i = 0; i < n; ++i) {
		if(t[i] != p[i % 3]) ok[0] = false;
		if(t[i] != p[(i + 1) % 3]) ok[1] = false;
		if(t[i] != p[(i + 2) % 3]) ok[2] = false;
	}

	ll ans = 0;
	if(ok[0]) ans += (len - n) / 3 + 1;
	if(ok[1]) ans += (len - n - 1) / 3 + 1;
	if(ok[2]) ans += (len - n - 2) / 3 + 1;

	cout << ans << '\n';

	return 0;
}

#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

map<int,int>Map;
int n, L, A[101000], w[101000], B[101000];
long long res = 0;
int LL[101000], RR[101000];
int PP[101000], QQ[101000];
int main(){
    int i;
    scanf("%d%d",&n,&L);
    for(i=1;i<=n;i++)scanf("%d",&A[i]);
    for(i=1;i<=n;i++)scanf("%d",&B[i]);
    A[n+1]=B[n+1]=L+1;
    int cnt=0;
    for(i=0;i<=n+1;i++){
        A[i]-=i,B[i]-=i;
        if(i==0 || A[i]!=A[i-1]){
            cnt++;
            LL[cnt]=i;
        }
        Map[A[i]]=cnt;
        RR[cnt]=i;
    }
    for(i=0;i<=n+1;i++){
        if(!Map.count(B[i])){
            puts("-1");
            return 0;
        }
        int x = Map[B[i]];
        if(i==0||B[i]!=B[i-1])PP[x]=i;
        QQ[x]=i;
    }
    for(i=1;i<=cnt;i++){
        if(!QQ[i])continue;
        if(QQ[i]>RR[i])res += QQ[i]-RR[i];
        if(PP[i]<LL[i])res += LL[i]-PP[i];
    }
    printf("%lld\n",res);
}