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

int main()
{
    size_t N, M;
    cin >> N >> M;

    vector<int> A(M + 2, 0);
    for (size_t i = 1; i <= M; i++)
    {
        cin >> A[i];
    }
    A.back() = N + 1;
    sort(A.begin(), A.end());

    map<int, size_t> count;
    int minimum = N;
    for (size_t i = 0; i <= M; i++)
    {
        if (A[i] + 1 == A[i + 1])
        {
            continue;
        }
        minimum = min(A[i + 1] - A[i] - 1, minimum);
        count[A[i + 1] - A[i] - 1]++;
    }
    int ans = 0;
    for (pair<int, size_t> c : count)
    {
        ans += (c.first + (minimum - 1)) / minimum * c.second;
    }
    cout << ans << endl;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int bm = 200001;
int BIT[bm];
void add(int A) {
	while (A > 0) {
		BIT[A]++;
		A -= A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A <= bm) {
		ret += BIT[A];
		A += A & -A;
	}
	return ret;
}
ll tmp[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N;
	cin >> N;
	ll A[200000], B[200000];
	rep1(i, N) cin >> A[i];
	rep1(i, N) cin >> B[i];
	rep1(i, N) A[i] += i * (1ll << 32 | 1);
	rep1(i, N) B[i] += i * (1ll << 32 | 1);

	pakuri_sort(N, A + 1);
	pakuri_sort(N, B + 1);

	rep1(i, N) {
		if ((A[i] ^ B[i]) & (1ll << 32) - 1) {
			co(-1);
			return 0;
		}
		tmp[A[i] >> 32] = B[i] >> 32;
	}
	ll kotae = 0;
	rep1(i, N) {
		kotae += query(tmp[i]);
		add(tmp[i]);
	}
	co(kotae);

	Would you please return 0;
}