#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <limits.h>
#include <string.h>
#include <math.h>

long long min(long long a, long long b){
    if (a < b) return a;
    return b;
}

int nod(int a, int b)
{
    while(a*b)
        a >= b ? a %= b : b %= a;
    return a + b;
}

int main(){
    int N, K;
    scanf("%i %i",&N,&K);
    int *mas = new int[N];
    int min = 1000000005;
    for (int i = 0; i < N; i++){
        scanf("%i",&mas[i]);
        if (mas[i] < min) min = mas[i];
    }

    long long sum = 0;
    for (int i = 0; i < N; i++){
        if ((mas[i] - min) % K != 0){ printf("-1"); return 0;}
        sum += (mas[i] - min) / K;
    }
    printf("%I64d",sum);
}


#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <limits.h>
#include <string.h>
#include <math.h>

long long min(long long a, long long b){
    if (a < b) return a;
    return b;
}

int nod(int a, int b)
{
    while(a*b)
        a >= b ? a %= b : b %= a;
    return a + b;
}

int main(){
    int N, K;
    scanf("%i %i",&N,&K);
    int *mas = new int[N];
    int min = 1000000005;
    int realgcd;
    for (int i = 0; i < N; i++){
        scanf("%i",&mas[i]);
        int gcd = mas[0];
        if (mas[i] < min) min = mas[i];
        realgcd = nod(gcd,mas[i]);
    }
    if (realgcd % K != 0){ printf("-1"); return 0;}
    long long sum = 0;
    for (int i = 0; i < N; i++){
        sum += (mas[i] - min) / K;
    }
    printf("%I64d",sum);
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    int a[100005];
    scanf("%d%d", &n, &k);
    int m = 0x3f3f3f3f;
    for(int i = 0; i < n; i++) {
        scanf("%d", a + i);
        m = min(m, a[i]);
    }
    long long sum = 0;
    for(int i = 0; i < n; i++) {
        if((a[i] - m) % k) {
            sum = -k;
            break;
        }
        sum += a[i] - m;
    }
    printf("%lld\n", sum / k);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    int a[100005];
    scanf("%d%d", &n, &k);
    int m = 0x3f3f3f3f;
    for(int i = 0; i < n; i++) {
        scanf("%d", a + i);
        m = min(m, a[i]);
    }
    long long sum = 0;
    for(int i = 0; i < n; i++)
        sum += a[i] - m;
    printf("%lld\n", sum % k ? -1 : sum / k);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    int a[100005];
    scanf("%d%d", &n, &k);
    int m = 0x3f3f3f3f;
    for(int i = 0; i < n; i++) {
        scanf("%d", a + i);
        m = min(m, a[i]);
    }
    long long sum = 0;
    for(int i = 0; i < n; i++) {
        if((a[i] - m) % k) {
            sum = -1;
            break;
        }
        sum += a[i] - m;
    }
    printf("%lld\n", sum);
    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define NMAX 100000
using namespace std;

int n, k;
int a[NMAX];

bool isAllEqual() {
    for (int i = 0; i < n; i++)
        if (a[i] != a[0])
            return false;
    return true;
}

int main(int argc, char** argv) {
    int min_number = 1000000000;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        min_number = min(min_number, a[i]);
    }
    long long second = 0;
    for (int i = 0; i < n; i++) {
        if ((a[i] - min_number) % k == 0)
            second += (a[i] - min_number) / k;
        else {
            printf("-1");
            return 0;
        }
    }
    printf("%I64d", second);
    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define NMAX 100000
using namespace std;

int n, k;
long long l;
int a[NMAX];

int gcd(int x, int y) {
    if (y > x) return gcd(y, x);
    if (x % y == 0)
        return y;
    else
        return gcd(y, x%y);
}

bool isAllEqual() {
    for (int i = 0; i < n; i++)
        if (a[i] != a[0])
            return false;
    return true;
}

int main(int argc, char** argv) {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    if (isAllEqual())
        printf("0");
    else {
        int g = a[0];
        int min_number = a[0];
        for (int i = 1; i < n; i++) {
            g = gcd(a[i], g);
            min_number = min(min_number, a[i]);
        }
        if (g % k != 0) {
            printf("-1");
        }
        else {
            long long r = 0;
            for (int i = 0; i < n; i++)
                r += (a[i] - min_number) / g;
            printf("%I64d", r);
        }
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const long long inf = 1000000010;
long long num[100005];
int main()
{
	int n;
	long long k;
	scanf("%d%I64d",&n,&k);
	long long sum = 0;
	long long mi = inf;
	for(int i=0;i<n;i++)
	{
		scanf("%I64d",&num[i]);
		mi = min(num[i],mi);
	}
	for(int i=0;i<n;i++)
	{
		if((num[i]-mi)%k!=0)
		{
			printf("-1\n");
			return 0;
		}
		sum+=(num[i]-mi)/k;
		//printf("%d\n",num[i]-mi);
	}
	printf("%I64d\n",sum);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const long long inf = 1000000010;
long long num[100005];
int main()
{
	int n;
	long long k;
	scanf("%d%I64d",&n,&k);
	int sum = 0;
	long long mi = inf;
	for(int i=0;i<n;i++)
	{
		scanf("%I64d",&num[i]);
		mi = min(num[i],mi);
	}
	for(int i=0;i<n;i++)
	{
		if((num[i]-mi)%k!=0)
		{
			printf("-1\n");
			return 0;
		}
		sum+=(num[i]-mi)/k;
		//printf("%d\n",num[i]-mi);
	}
	printf("%I64d\n",sum);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int inf = 1<<30;
long long num[100005];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int sum = 0;
	long long mi = inf;
	for(int i=0;i<n;i++)
	{
		scanf("%I64d",&num[i]);
		mi = min(num[i],mi);
	}
	for(int i=0;i<n;i++)
	{
		if((num[i]-mi)%k!=0)
		{
			printf("-1\n");
			return 0;
		}
		sum+=(num[i]-mi)/k;
		//printf("%d\n",num[i]-mi);
	}
	printf("%I64d\n",sum);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int inf = 1<<30;
int num[100005];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int sum = 0;
	int mi = inf;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
		mi = min(num[i],mi);
	}
	for(int i=0;i<n;i++)
	{
		if((num[i]-mi)%k!=0)
		{
			printf("-1\n");
			return 0;
		}
		sum+=(num[i]-mi)/k;
		//printf("%d\n",num[i]-mi);
	}
	printf("%I64d\n",sum);
	return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int a[100010];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int mini = inf;

	for(int i = 0; i < n; i++) {
		scanf("%I64d", &a[i]);
	}

	for(int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
	}
	ll aux = 0;
	bool pode = true;
	for(int i = 0; i < n; i++) {
		aux += (a[i] - mini) / k;
		if((a[i] - mini)%k != 0) pode = false;
	}

	if(pode) printf("%I64d\n", aux);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int a[100010];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int resp = 0;

	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		resp = __gcd(resp, a[i]);
	}
	int mini = inf;

	for(int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
	}
	ll aux = 0;
	for(int i = 0; i < n; i++) {
		aux += (a[i] - mini);
	}

	if(aux%k == 0 || aux%resp == 0) printf("%I64d\n", aux / k);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int a[100010];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int mini = inf;

	for(int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
	}
	ll aux = 0;
	bool pode = true;
	for(int i = 0; i < n; i++) {
		aux += (a[i] - mini) / k;
		if((a[i] - mini)%k != 0) pode = false;
	}

	if(pode) printf("%I64d\n", aux);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int a[100010];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int resp = 0;

	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		resp = __gcd(resp, a[i]);
	}
	int mini = inf;

	for(int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
	}
	ll aux = 0;
	for(int i = 0; i < n; i++) {
		aux += (a[i] - mini);
	}
	aux /= k;
	if(aux && (resp%k == 0 || k%resp == 0)) printf("%I64d\n", aux);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int a[100010];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int resp = 0;

	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		resp = __gcd(resp, a[i]);
	}
	int mini = inf;

	for(int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
	}
	ll aux = 0;
	for(int i = 0; i < n; i++) {
		aux += (a[i] - mini);
	}

	if(aux%k == 0 && (k%resp == 0 || resp%k == 0)) printf("%I64d\n", aux / k);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int a[100010];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int mini = inf;

	for(int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
	}
	ll aux = 0;
	bool pode = true;
	for(int i = 0; i < n; i++) {
		aux += (a[i] - mini);
		if((a[i] - mini)%k != 0) pode = false;
	}

	if(pode) printf("%I64d\n", aux / k);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int resp = 0;
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		resp = __gcd(resp, x);
	}

	if(resp > 1) printf("%d\n", resp);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int a[100010];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int resp = 0;

	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		resp = __gcd(resp, a[i]);
	}
	int mini = inf;

	for(int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
	}
	ll aux = 0;
	for(int i = 0; i < n; i++) {
		aux += (a[i] - mini);
	}

	if(aux%k == 0) printf("%I64d\n", aux / k);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main() {
	ll n, k;
	scanf("%I64d %I64d", &n, &k);

	ll resp = 0;
	for(int i = 0; i < n; i++) {
		ll x;
		scanf("%I64d", &x);
		resp = gcd(resp, x);
	}

	if(resp > 1) printf("%I64d\n", resp);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

#define fr(a, b, c) for(int a = b; a < c; ++a)
#define pb push_back
#define MOD 1000000007
#define fi first
#define sec second
#define EPS 10e-9

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3fLL;

int a[100010];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);

	int resp = 0;

	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		resp = __gcd(resp, a[i]);
	}
	int mini = inf;

	for(int i = 0; i < n; i++) {
		mini = min(mini, a[i]);
	}
	ll aux = 0;
	for(int i = 0; i < n; i++) {
		aux += (a[i] - mini);
	}
	aux /= k;
	if(aux) printf("%I64d\n", aux);
	else printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int r[100000];

int main() {
//	freopen("f", "r", stdin);
	int n, k, mi = 1e9 + 1;
	cin >> n >> k;
	bool ok = 1;
	for (int i = 0; i < n; ++i) {
		cin >> r[i];
		mi = min(mi, r[i]);
	}
	long long answ = 0;
	for (int i = 0; i < n; ++i) {
		if ((r[i] - mi) % k) {
			ok = 0;
			break;
		}
		answ += (long long) ((r[i] - mi) / k);
	}
	if (ok)
		cout << answ << endl;
	else
		cout << -1 << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int r[100000];

int main() {
//	freopen("f", "r", stdin);
	int n, k, mi = 1e9 + 1;
	cin >> n >> k;
	bool ok = 1;
	for (int i = 0; i < n; ++i) {
		cin >> r[i];
		mi = min(mi, r[i]);
		if (r[i] % k) {
			ok = 0;
			break;
		}
	}
	if (ok) {
		long long answ = 0;
		for (int i = 0; i < n; ++i) {
			answ += (long long)((r[i] - mi) / k);
		}
		cout << answ << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int r[100000];

int main() {
//	freopen("f", "r", stdin);
	int n, k, mi = 1e9 + 1;
	cin >> n >> k;
	bool ok = 1;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		cin >> r[i];
		mi = min(mi, r[i]);
		if (r[i] % k) {
			ok = 0;
		}
	}
	for (int i = 0; i < n; ++i) {
		if(r[i] == mi)
			cnt++;
	}
	if (n == 1 || cnt == n)
		cout << 0 << endl;
	else {
		if (ok) {
			long long answ = 0;
			for (int i = 0; i < n; ++i) {
				answ += (long long) ((r[i] - mi) / k);
			}
			cout << answ << endl;
		} else {
			cout << -1 << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int r[100000];

int main() {
//	freopen("f", "r", stdin);
	int n, k, mi = 1e9 + 1;
	cin >> n >> k;
	bool ok = 1;
	for (int i = 0; i < n; ++i) {
		cin >> r[i];
		mi = min(mi, r[i]);
		if (r[i] % k) {
			ok = 0;
			break;
		}
	}
	if (n == 1)
		cout << 0 << endl;
	else {
		if (ok) {
			long long answ = 0;
			for (int i = 0; i < n; ++i) {
				answ += (long long) ((r[i] - mi) / k);
			}
			cout << answ << endl;
		} else {
			cout << -1 << endl;
		}
	}
	return 0;
}


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

int main()
{
	long long n,k,temp,ans;
	cin>> n >>k ;
	long long a[n+2];
	for(long long i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);

    ans=0;

    for(long long i=1;i<n;i++)
    {
        temp=a[i]-a[0];
        if (temp%k!=0)
        {
            cout<<"-1\n";
            return 0;
        }
        ans+=temp/k;
    }
    cout<<ans<< endl;
	return 0;
}


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

int main()
{
	long long n,k,min,ans;
	cin>> n >>k ;
	int flag=1;
	long long a[n+2];
	min=9999999999;
	for(long long i=0;i<n;i++)
	{
		cin>> a[i];
		if(a[i]%k !=0) flag=0;
		if(a[i] < min) min=a[i];
	}
	if(flag==0) {cout << "-1"; return 0;}
	//cout << min << endl;
	//sort(a,a+n);
	ans=0;
	for(long long i=0;i<n;i++)
	{
		ans+= (a[i]-min);
	}
	cout << ans/k << endl;
	return 0;
}


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

int main()
{
	long long n,k,min,ans;
	cin>> n >>k ;
	int flag=1;
	long long a[n+2];
	min=9999999999;
	for(long long i=0;i<n;i++)
	{
		cin>> a[i];
		if(a[i]%k !=0) flag=0;
		if(a[i] < min) min=a[i];
	}
	if(n==1) {cout<< "0" << endl; return 0;}
	if(flag==0) {cout << "-1"; return 0;}
	//cout << min << endl;
	//sort(a,a+n);
	ans=0;
	for(long long i=0;i<n;i++)
	{
		ans+= (a[i]-min);
	}
	cout << ans/k << endl;
	return 0;
}


#include<stdio.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    long long min=100000000000,ans=0;
    int flag=0,i;
    long long shareprice[n];
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&shareprice[i]);
        if(shareprice[i]<min)
        {
            min=shareprice[i];
        }

    }
    for(i=0;i<n;i++)
    {
        if((shareprice[i]-min) %k!=0)
        {
            ans=ans+(shareprice[i]-min)/k;
            flag=1;

        }
        flag=2;

    }

    if(flag==1)
        printf("%I64d",ans);
    else if(flag==2)
        printf("-1");

    return 0;
}


#include<stdio.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    long long min=100000000000,ans=0;
    int flag=0,i;
    long long shareprice[n];
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&shareprice[i]);
        if(shareprice[i]<min)
        {
            min=shareprice[i];
        }

    }
    for(i=0;i<n;i++)
    {
        if((shareprice[i]-min) %k!=0)
        {

            flag=1;

        }
        ans=ans+(shareprice[i]-min)/k;

    }

    if(flag==0)
        printf("%I64d",ans);
    else if(flag==1)
        printf("-1");

    return 0;
}


#include<stdio.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    long long min=100000000000,res,ans=0;
    int flag=0,i;
    long long shareprice[n];
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&shareprice[i]);
        if(shareprice[i]<min)
        {
            min=shareprice[i];
        }

    }
    for(i=0;i<n;i++)
    {
        if((shareprice[i]-min) %k==0)
        {
            res=(shareprice[i]-min)/k;
            ans=ans+res;
            flag=1;
        }
        else
        {
            printf("-1");
            break;
        }

    }

    if(flag==1)
        printf("%I64d",ans);

    return 0;
}


#include<stdio.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    long long min=100000000000,res,ans=0;
    int flag=0,i;
    long long shareprice[n];
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&shareprice[i]);
        if(shareprice[i]<min)
        {
            min=shareprice[i];
        }
        if((shareprice[i]-min) %k==0)
        {
            res=(shareprice[i]-min)/k;
            ans=ans+res;
            flag=1;
        }

    }
    if(flag==1)
        printf("%I64d",ans);
    else
        printf("-1");

    return 0;
}


#include<stdio.h>
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    long long min=100000000000,res,ans=0;
    int flag=0,i;
    long long shareprice[n];
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&shareprice[i]);
        if(shareprice[i]<min)
        {
            min=shareprice[i];
        }

    }
    for(i=0;i<n;i++)
    {
        if((shareprice[i]-min) %k==0)
        {
            res=(shareprice[i]-min)/k;
            ans=ans+res;
            flag=1;
        }
    }
    if(flag==1)
        printf("%I64d",ans);
    else
        printf("-1");

    return 0;
}


#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int MOD=1e9+7,N=100005;
const int INF=1e8;
int n,k,a[N];
int M,ans,P;
int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)cin>>a[i];
	M=a[1];
	for (int i=2;i<=n;i++)M=min(M,a[i]);
	for (int i=1;i<=n;i++){
		if ((a[i]-M)%k)P=1;
		ans+=(a[i]-M)/k;
	}
	if (P)ans=-1;
	cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int MOD=1e9+7,N=100005;
const int INF=1e8;
int n,k,a[N];
ll M,ans,P;
int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)cin>>a[i];
	M=a[1];
	for (int i=2;i<=n;i++)M=min(M,a[i]);
	cout<<M<<endl;
	for (int i=1;i<=n;i++){
		if ((a[i]-M)%k)P=1;
		ans+=(a[i]-M)/k;
		cout<<(a[i]-M)/k<<endl;
	}
	if (P)ans=-1;
	cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int MOD=1e9+7,N=100005;
const int INF=1e8;
int n,k,a[N];
ll M,ans,P;
int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)cin>>a[i];
	M=a[1];
	for (int i=2;i<=n;i++)M=MIN(M,a[i]);
	cout<<M<<endl;
	for (int i=1;i<=n;i++){
		if ((a[i]-M)%k)P=1;
		ans+=(a[i]-M)/k;
		cout<<(a[i]-M)/k<<endl;
	}
	if (P)ans=-1;
	cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int MOD=1e9+7,N=100005;
const int INF=1e8;
ll n,k,a[N];
ll M,ans,P;
int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)cin>>a[i];
	M=a[1];
	for (int i=2;i<=n;i++)M=MIN(M,a[i]);
	for (int i=1;i<=n;i++){
		if ((a[i]-M)%k)P=1;
		ans+=(a[i]-M)/k;
	}
	if (P)ans=-1;
	cout<<ans<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,k,z=0;
    cin >>n>>k;
    long int a[n],i,min;
    long long int v=0;
    for(i=0;i<n;i++)
    {
        cin >>a[i];
    }
    min=a[0];
    for(i=0;i<n;i++)
    {
        if(min>a[i])
            min=a[i];
    }
    for(i=0;i<n;i++)
    {
            if((a[i]-min)%k==0)
               {
                v+=(a[i]-min)/k;
                z++;
               }
    }
    if(z==n)
        cout<<v;
    else
        cout<<"-1";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,k,z=0;
    cin >>n>>k;
    long int a[n],i,v=0,min;
    for(i=0;i<n;i++)
    {
        cin >>a[i];
    }
    min=a[0];
    for(i=0;i<n;i++)
    {
        if(min>a[i])
            min=a[i];
    }
    for(i=0;i<n;i++)
    {
            if((a[i]-min)%k==0)
               {
                v=v+(a[i]-min)/k;
                z++;
               }
    }
    if(z==n)
        cout<<v;
    else
        cout<<"-1";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,k,z=0;
    cin >>n>>k;
    long int a[n],i,v=0,min;
    for(i=0;i<n;i++)
    {
        cin >>a[i];
    }
    min=a[0];
    for(i=0;i<n;i++)
    {
        if(min>a[i])
            min=a[i];
    }
    for(i=0;i<n;i++)
    {
        while(a[i]>min)
        {
            a[i]-=k;
            v++;
        }
    }
    for(i=0;i<n;i++)
    {
        if(a[i]==min)
            z++;
    }
    if(z==n)
        cout<<v;
    else
        cout<<"-1";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,k,z=0;
    cin >>n>>k;
    long long int a[n],i,v=0,min;
    for(i=0;i<n;i++)
    {
        cin >>a[i];
    }
    min=a[0];
    for(i=0;i<n;i++)
    {
        if(min>a[i])
            min=a[i];
    }
    for(i=0;i<n;i++)
    {
        while(a[i]>min)
        {
            a[i]-=k;
            v++;
        }
    }
    for(i=0;i<n;i++)
    {
        if(a[i]==min)
            z++;
    }
    if(z==n)
        cout<<v;
    else
        cout<<"-1";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,k,z=0;
    cin >>n>>k;
    long int a[n],i,v=0,min;
    for(i=0;i<n;i++)
    {
        cin >>a[i];
    }
    min=a[0];
    for(i=0;i<n;i++)
    {
        if(min>a[i])
            min=a[i];
    }
    for(i=0;i<n;i++)
    {
        while(a[i]>min)
        {
            a[i]-=k;
            v++;
        }
            if(a[i]==min)
                z++;
    }
    if(z==n)
        cout<<v;
    else
        cout<<"-1";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 long long n,m,a[100004],c;
int main()
{
    ios::sync_with_stdio(0),cin.tie();
    cin >> n >> m;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];

        c += (a[i]%m == 0);
    }

    sort(a,a+n);

  long long x = a[0],res = 0,kk = 1;

   for(int i=1;i<n;i++)
   {
       kk += (x == a[i]);
       res += (a[i] - x)/m;

   }
   if(c != n && kk != n)
   {
       cout << -1;
       return 0;
   }
   cout << res;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 long long n,m,a[100004],c,res;
int main()
{
    ios::sync_with_stdio(0),cin.tie();
    cin >> n >> m;
   for(int i=0;i<n;i++)
    cin >> a[i];
    sort(a,a+n);
    long long mn = a[0];

    for(int i=1;i<n;i++)
    {
        if((a[i] - mn)%m == 0)
           res += (a[i] - mn)/m;
        else{
            cout << -1;
            return 0;
        }
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long n,m,a[100004],c;
int main()
{
    cin >> n >> m;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        c += (a[i]%m == 0);
    }
    sort(a,a+n);
   if(c != n)
   {
       cout << -1;
       return 0;
   }
  long long x = a[0],res = 0;

   for(int i=1;i<n;i++)
   {
       res += (a[i] - x)/m;

   }
   cout << res;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 unsigned long long n,m,a[100004],c;
int main()
{
    ios::sync_with_stdio(0),cin.tie();
    cin >> n >> m;
    for(int i=0; i<n; i++)
    {
        cin >> a[i];
        if(__gcd(a[i],m) != 1 || m == 1)
            c++;
    }
    long long x2 = a[0],kk = 0;
   for(int i=0;i<n;i++)
   {
       if(x2 == a[i])
         kk++;
   }
   if(kk == n)
   {
       cout << 0;
       return 0;
   }
    sort(a,a+n);
  unsigned long long x = a[0],res = 0;

   for(int i=0;i<n;i++)
   {
       if(x != a[i])
        res += ((a[i] - x)/m);

   }
   if(c != n)
   {
       cout << -1;
       return 0;
   }
   cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,n,i,j,c=0,s,ans,sum=0;
    cin>>n>>k;
    long long int a[n+5];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    if(n==1)
    {
        cout<<"0"<<endl;

    }
    else
    {
        for(j=n-1; j>0; j--)
        {
            if(a[j]>a[0])
            {
                a[j]-=a[0];
                if((a[j]%k)==0)
                {
                    sum+=a[j]/k;
                }
                else
                {
                    c=1;
                    break;
                }
            }
        }
        if(c!=1)
            cout<<sum<<endl;
        else
            cout<<"-1"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,n,i,j,c=0,s,ans;
    cin>>n>>k;
    long long int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(j=n-1;j>0;j--)
    {
        s=a[j];
        while(s!=a[0])
        {
            s-=k;
            c++;
            if(s<a[0])
            {
                ans=0;
                break;
            }
        }
    }
    if(ans!=0)
    cout<<c<<endl;
    else
        cout<<"-1"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a[100005],b,c=0,n,k,sum=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
        for(int i=1;i<n-1;i++)
        {
            if((a[i]-k)<a[0])
            {
                cout<<"-1"<<endl;
                c=1;
                break;
            }
        }
        if(c!=1){
    for(int j=n-1;j>0;j--)
    {
        sum+=(a[j]-a[0]);
    }
    if(sum%k==0)
    {
        cout<<sum/k<<endl;

    }
    else
        cout<<"-1"<<endl;
        }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a[100005],b,c=0,n,k,sum=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
        for(int i=1;i<n-1;i++)
        {
            if(a[i]!=a[0])
            {
                if((a[i]-k)<a[0]){
                cout<<"-1"<<endl;
                c=1;
                break;}
            }
        }
        if(c!=1){
    for(int j=n-1;j>0;j--)
    {
        sum+=(a[j]-a[0]);
    }
    if(sum%k==0)
    {
        cout<<sum/k<<endl;

    }
    else
        cout<<"-1"<<endl;
        }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a[100005],b,c,n,k,sum=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int j=n-1;j>0;j--)
    {
        sum+=(a[j]-a[0]);
    }
    if(sum%k==0)
    {
        cout<<sum/k<<endl;

    }
    else
        cout<<"-1"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,n,i,j,c=0,s,ans;
    cin>>n>>k;
    long long int a[n+5];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    if(n==1)
    {
        cout<<"0"<<endl;

    }
    else
    {
        for(j=n-1; j>0; j--)
        {
            a[j]-=a[0];
            if((a[j]%k)==0)
            {
                c+=a[j]/k;
            }
            else
            {
                c=0;
                break;
            }
        }
        if(c!=0)
            cout<<c<<endl;
        else
            cout<<"-1"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int k,n,i,j,c=0,s,ans;
    cin>>n>>k;
    long long int a[n+5];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(j=n-1;j>0;j--)
    {
          a[j]-=a[0];
          if((a[j]%k)==0)
          {
              c+=a[j]/k;
          }
          else
            {
                c=0;
                break;
            }
    }
    if(c!=0)
    cout<<c<<endl;
    else
        cout<<"-1"<<endl;
    return 0;
}


#include<iostream>
#include<climits>
#include<vector>
using namespace std;

int main()
{
    int n, k;
    cin>>n>>k;
    long int a[n] = {0};
    long int mini =  INT_MAX;
    int yes = 0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]%k != 0)
        {
            yes = 1;
            break;
        }
        if(mini>a[i])
        {
            mini = a[i];
        }
    }

    long long int ans = 0;
    if(yes == 0)
    {
        for(int i =0; i<n; i++)
        {
            ans+= (a[i]-mini)/k;

        }
    }
    else
        ans = -1;

    cout<<ans;

}


#include<iostream>
#include<climits>
#include<vector>
using namespace std;

int main()
{
    int n, k;
    cin>>n>>k;
    long int a[n] = {0};
    long int mini =  INT_MAX;
    int yes = 0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(mini>a[i])
        {
            mini = a[i];
        }
    }

    long long int ans = 0;
    for(int i =0; i<n; i++)
    {
        if((a[i]-mini)%k != 0)
        {
            yes = 1;
            break;
        }
        ans+= (a[i]-mini)/k;

    }

    if(yes == 1)
        ans = -1;

    cout<<ans;

}


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

int n,k,a[100005];
long long timer;
int main()
{
cin>>n>>k;
for (int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for(int i=2;i<=n;i++)
	{
		if((a[i]-a[1])%k) return cout<<-1,0;
		timer+=(a[i]-a[1])/k;
	}
cout<<timer;
    return 0;
}


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

int n,k,a[100005],timer;
int main()
{
cin>>n>>k;
for (int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for(int i=2;i<=n;i++)
	{
		if((a[i]-a[1])%k) return cout<<-1,0;
		timer+=(a[i]-a[1])/k;
	}
cout<<timer;
    return 0;
}


/***************************************************DarkdreamOFmy**********************************************************/
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

typedef                                     long int li;
typedef                                     long long int lli;
typedef                                     unsigned long long int ull;
typedef                                     signed long long int sll;
typedef                                     long double lld;
typedef                                     vector<int>vi;
typedef                                     vector<long>vl;
typedef                                     vector<long long int>vll;
typedef                                     vector<double>vd;
typedef                                     vector<long double>vld;
typedef                                     vector<char>vc;
typedef                                     vector<string>vs;
typedef                                     pair<int,int>pii;
typedef                                     pair<long long,long long>pll;
typedef                                     pair<double,double>pdd;
typedef                                     pair<char,char>pcc;
typedef                                     pair<string,string>pss;
typedef                                     map<int,int>mii;
typedef                                     map<long long,long long>mll;
typedef                                     map<char,char>mcc;
typedef                                     map<string,string>mss;
typedef                                     map<string,int>msi;
typedef                                     map< int,vector<int> >miv;
typedef                                     map<vector<int>,vector<int> >mvvi;
typedef                                     map<string,vector<int> >msv;
typedef                                     set<int>si;
typedef                                     set<string>ss;
typedef                                     set<vector<int> >sv;
typedef                                     queue<int>qi;
typedef                                     queue<long long>qll;
typedef                                     queue<string>qs;
typedef                                     stack<int>stki;
typedef                                     stack<long long>stkll;

/**-------------------END OF typedef------------------------------**/

const int                                   INF  = 1000000000;
const int                                   MAX  = 4007;
const int                                   MAX2 = 1000000;
const int                                   MAXD = 20;
const int                                   BASE = 1000000007;
const int                                   MOD  = 1000000007;
const int                                   psz  = 2000006;

/**-------------------Constant int--------------------------------**/

#define sI(a)                               scanf("%d",&a)
#define sI2(a,b)                            sI(a) , sI(b)
#define sI3(a,b,c)                          sI(a), sI(b), sI(c)
#define sI4(a,b,c,d)                        sI(a), sI(b), sI(c), sI(d)

#define sL(a)                               scanf("%lld",&a)
#define sL2(a,b)                            sL(a) , sL(b)
#define sL3(a,b,c)                          sL(a), sL(b), sL(c)
#define sL4(a,b,c,d)                        sL(a), sL(b), sL(c), sL(d)

#define pI(a)                               printf("%d",a)
#define pI2(a,b)                            pI(a) , pI(b)
#define pI3(a,b,c)                          pI(a), pI(b), pI(c)
#define pI4(a,b,c,d)                        pI(a), pI(b), pI(c), pI(d)

#define pL(a)                               printf("%lld",a)
#define pL2(a,b)                            pL(a) , pL(b)
#define pL3(a,b,c)                          pL(a), pL(b), pL(c)
#define pL4(a,b,c,d)                        pL(a), pL(b), pL(c), pL(d)

/**----------------------Scan and print end--------------------------**/

#define min3(a,b,c)                         min(a,min(b,c))
#define max3(a,b,c)                         max(a,max(b,c))
#define min4(a,b,c,d)                       min(min(a,b),min(c,d))
#define max4(a,b,c,d)                       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)                     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)                     min(min3(a,b,c),min(d,e))

/**----------------------MAX and MIN end-----------------------------**/

#define fst                                 first
#define snd                                 second
#define all(a)                              a.begin(),a.end()
#define rall(a)                             a.rbegin(),a.rend()
#define SQR(a)                              ((a)*(a))
#define Unique(a)                           sort(all(a)),a.erase(unique(all(a)),a.end())
#define Iterator(a)                         __typeof__(a.begin())
#define rIterator(a)                        __typeof__(a.rbegin())
#define FORI(a,it)                          for(Iterator(a) it = a.begin();it != a.end(); it++)
#define RFORI(a,it)                         for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FOR(i, a, b)                        for(int i=(a);i<(b);i++)
#define RFOR(i, b, a)                       for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value)                       memset(A,value,sizeof(A))
#define SZ(V)                               (int)V.size()
#define PB                                  push_back
#define MP                                  make_pair
#define Pi                                  3.14159265358979
#define read(x)                             freopen(x, "r", stdin)
#define write(x)                            freopen(x, "w", stdout)

/**---------------------End of define of all----------------------**/

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

/**-----------------------Directional------------------------------**/

inline int number_of_edges(int degreeofvertices)   {int res; res=(degreeofvertices)/2;return res;};
inline int josephus(int n,int k)                   {if(n==1){return 1;}else{return (josephus(n-1,k)+k-1)%n+1;}}

/**-----------------------Normal equations-------------------------**/

inline int binary_src(int a[],int n,int k)         {int lo=0,hi=n-1,mid;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]==k){return mid+1;}else if(a[mid]>k){hi=mid-1;}else if(a[mid]<k){lo=mid+1;}}return -1;}
inline bool isLeap(lli y)                          {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }
inline int chToIn(char a)                          {int b;b = a-'0';return b;}
inline char inTOch(int a)                          {char b;b= a+'0';return b;}
inline int stToIn(string a)                        {int b;b=atoi(a.c_str());return b;}
inline string appendChar(string s,char a)          {s.append(1,a);return s;}
inline string rev(string a)                        {int siz=SZ(a);string res="";RFOR(i,siz,0){res+=a[i];}return res;}
inline int gcd(int a, int b)                       {return (b == 0 ? a : gcd(b, a % b));}
inline int lcm(int a, int b)                       {return (a * (b / gcd(a, b))); }
vll factors_n; inline lli factor_find_n(lli n)     {for(lli i=2; i<=n; i++)while(n%i==0){n/=i; factors_n.PB(i);}}
vll factors_sqr; inline lli factor_find_sqrt(lli n){for(lli i=2; i*i<=n; i++)while(n%i==0){n/=i; factors_sqr.PB(i);}}
inline lli bigmod(lli a,lli b,lli m)               {if(b==0)return 1%m;lli x=bigmod(a,b/2,m);x=(x*x)%m;if(b%2==1){x=(x*a)%m;}return x;}
inline lli phi(lli n)                              {lli ret=n;for(lli i=2; i*i<=n; i++){if(n%i==0){while(n%i==0)n/=i;}ret-=ret/i;}if(n>1){ret-=ret/n;}return ret;}

/**---------------------End of functions--------------------------**/

int main(){
    lli n,k;
    sL2(n,k);
    lli sum=0;
   // lli mn=INF*2+500000;
    lli a[n+10];
    FOR(i,0,n){
        sL(a[i]);
       // mn=min(a[i],mn);
    }
    sort(a,a+n);
    FOR(i,1,n){
        if(abs(a[i]-a[0])%k==0){
            sum+=abs(a[i]-a[0]);
        }
        else{
            cout<<-1;
            return 0;
        }
    }
    lli res=sum/k;
    if(sum%k==0){
        pL(res);
    }
    else{
        cout<<-1;
    }
    return 0;
}


/***************************************************DarkdreamOFmy**********************************************************/
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

typedef                                     long int li;
typedef                                     long long int lli;
typedef                                     unsigned long long int ull;
typedef                                     signed long long int sll;
typedef                                     long double lld;
typedef                                     vector<int>vi;
typedef                                     vector<long>vl;
typedef                                     vector<long long int>vll;
typedef                                     vector<double>vd;
typedef                                     vector<long double>vld;
typedef                                     vector<char>vc;
typedef                                     vector<string>vs;
typedef                                     pair<int,int>pii;
typedef                                     pair<long long,long long>pll;
typedef                                     pair<double,double>pdd;
typedef                                     pair<char,char>pcc;
typedef                                     pair<string,string>pss;
typedef                                     map<int,int>mii;
typedef                                     map<long long,long long>mll;
typedef                                     map<char,char>mcc;
typedef                                     map<string,string>mss;
typedef                                     map<string,int>msi;
typedef                                     map< int,vector<int> >miv;
typedef                                     map<vector<int>,vector<int> >mvvi;
typedef                                     map<string,vector<int> >msv;
typedef                                     set<int>si;
typedef                                     set<string>ss;
typedef                                     set<vector<int> >sv;
typedef                                     queue<int>qi;
typedef                                     queue<long long>qll;
typedef                                     queue<string>qs;
typedef                                     stack<int>stki;
typedef                                     stack<long long>stkll;

/**-------------------END OF typedef------------------------------**/

const int                                   INF  = 1000000000;
const int                                   MAX  = 4007;
const int                                   MAX2 = 1000000;
const int                                   MAXD = 20;
const int                                   BASE = 1000000007;
const int                                   MOD  = 1000000007;
const int                                   psz  = 2000006;

/**-------------------Constant int--------------------------------**/

#define sI(a)                               scanf("%d",&a)
#define sI2(a,b)                            sI(a) , sI(b)
#define sI3(a,b,c)                          sI(a), sI(b), sI(c)
#define sI4(a,b,c,d)                        sI(a), sI(b), sI(c), sI(d)

#define sL(a)                               scanf("%lld",&a)
#define sL2(a,b)                            sL(a) , sL(b)
#define sL3(a,b,c)                          sL(a), sL(b), sL(c)
#define sL4(a,b,c,d)                        sL(a), sL(b), sL(c), sL(d)

#define pI(a)                               printf("%d",a)
#define pI2(a,b)                            pI(a) , pI(b)
#define pI3(a,b,c)                          pI(a), pI(b), pI(c)
#define pI4(a,b,c,d)                        pI(a), pI(b), pI(c), pI(d)

#define pL(a)                               printf("%lld",a)
#define pL2(a,b)                            pL(a) , pL(b)
#define pL3(a,b,c)                          pL(a), pL(b), pL(c)
#define pL4(a,b,c,d)                        pL(a), pL(b), pL(c), pL(d)

/**----------------------Scan and print end--------------------------**/

#define min3(a,b,c)                         min(a,min(b,c))
#define max3(a,b,c)                         max(a,max(b,c))
#define min4(a,b,c,d)                       min(min(a,b),min(c,d))
#define max4(a,b,c,d)                       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)                     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)                     min(min3(a,b,c),min(d,e))

/**----------------------MAX and MIN end-----------------------------**/

#define fst                                 first
#define snd                                 second
#define all(a)                              a.begin(),a.end()
#define rall(a)                             a.rbegin(),a.rend()
#define SQR(a)                              ((a)*(a))
#define Unique(a)                           sort(all(a)),a.erase(unique(all(a)),a.end())
#define Iterator(a)                         __typeof__(a.begin())
#define rIterator(a)                        __typeof__(a.rbegin())
#define FORI(a,it)                          for(Iterator(a) it = a.begin();it != a.end(); it++)
#define RFORI(a,it)                         for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FOR(i, a, b)                        for(int i=(a);i<(b);i++)
#define RFOR(i, b, a)                       for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value)                       memset(A,value,sizeof(A))
#define SZ(V)                               (int)V.size()
#define PB                                  push_back
#define MP                                  make_pair
#define Pi                                  3.14159265358979
#define read(x)                             freopen(x, "r", stdin)
#define write(x)                            freopen(x, "w", stdout)

/**---------------------End of define of all----------------------**/

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

/**-----------------------Directional------------------------------**/

inline int number_of_edges(int degreeofvertices)   {int res; res=(degreeofvertices)/2;return res;};
inline int josephus(int n,int k)                   {if(n==1){return 1;}else{return (josephus(n-1,k)+k-1)%n+1;}}

/**-----------------------Normal equations-------------------------**/

inline int binary_src(int a[],int n,int k)         {int lo=0,hi=n-1,mid;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]==k){return mid+1;}else if(a[mid]>k){hi=mid-1;}else if(a[mid]<k){lo=mid+1;}}return -1;}
inline bool isLeap(lli y)                          {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }
inline int chToIn(char a)                          {int b;b = a-'0';return b;}
inline char inTOch(int a)                          {char b;b= a+'0';return b;}
inline int stToIn(string a)                        {int b;b=atoi(a.c_str());return b;}
inline string appendChar(string s,char a)          {s.append(1,a);return s;}
inline string rev(string a)                        {int siz=SZ(a);string res="";RFOR(i,siz,0){res+=a[i];}return res;}
inline int gcd(int a, int b)                       {return (b == 0 ? a : gcd(b, a % b));}
inline int lcm(int a, int b)                       {return (a * (b / gcd(a, b))); }
vll factors_n; inline lli factor_find_n(lli n)     {for(lli i=2; i<=n; i++)while(n%i==0){n/=i; factors_n.PB(i);}}
vll factors_sqr; inline lli factor_find_sqrt(lli n){for(lli i=2; i*i<=n; i++)while(n%i==0){n/=i; factors_sqr.PB(i);}}
inline lli bigmod(lli a,lli b,lli m)               {if(b==0)return 1%m;lli x=bigmod(a,b/2,m);x=(x*x)%m;if(b%2==1){x=(x*a)%m;}return x;}
inline lli phi(lli n)                              {lli ret=n;for(lli i=2; i*i<=n; i++){if(n%i==0){while(n%i==0)n/=i;}ret-=ret/i;}if(n>1){ret-=ret/n;}return ret;}

/**---------------------End of functions--------------------------**/

int main(){
    lli n,k;
    sL2(n,k);
    lli sum=0;
    lli mn=INF*2;
    lli a[n+10];
    FOR(i,0,n){
        sL(a[i]);
        mn=min(a[i],mn);
    }
    FOR(i,0,n){
        sum+=abs(mn-a[i]);
    }
    lli res=sum/k;
    if(res){
        pL(res);
    }
    else{
        res=-1;
        pL(res);
    }
    return 0;
}


/***************************************************DarkdreamOFmy**********************************************************/
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

typedef                                     long int li;
typedef                                     long long int lli;
typedef                                     unsigned long long int ull;
typedef                                     signed long long int sll;
typedef                                     long double lld;
typedef                                     vector<int>vi;
typedef                                     vector<long>vl;
typedef                                     vector<long long int>vll;
typedef                                     vector<double>vd;
typedef                                     vector<long double>vld;
typedef                                     vector<char>vc;
typedef                                     vector<string>vs;
typedef                                     pair<int,int>pii;
typedef                                     pair<long long,long long>pll;
typedef                                     pair<double,double>pdd;
typedef                                     pair<char,char>pcc;
typedef                                     pair<string,string>pss;
typedef                                     map<int,int>mii;
typedef                                     map<long long,long long>mll;
typedef                                     map<char,char>mcc;
typedef                                     map<string,string>mss;
typedef                                     map<string,int>msi;
typedef                                     map< int,vector<int> >miv;
typedef                                     map<vector<int>,vector<int> >mvvi;
typedef                                     map<string,vector<int> >msv;
typedef                                     set<int>si;
typedef                                     set<string>ss;
typedef                                     set<vector<int> >sv;
typedef                                     queue<int>qi;
typedef                                     queue<long long>qll;
typedef                                     queue<string>qs;
typedef                                     stack<int>stki;
typedef                                     stack<long long>stkll;

/**-------------------END OF typedef------------------------------**/

const int                                   INF  = 1000000000;
const int                                   MAX  = 4007;
const int                                   MAX2 = 1000000;
const int                                   MAXD = 20;
const int                                   BASE = 1000000007;
const int                                   MOD  = 1000000007;
const int                                   psz  = 2000006;

/**-------------------Constant int--------------------------------**/

#define sI(a)                               scanf("%d",&a)
#define sI2(a,b)                            sI(a) , sI(b)
#define sI3(a,b,c)                          sI(a), sI(b), sI(c)
#define sI4(a,b,c,d)                        sI(a), sI(b), sI(c), sI(d)

#define sL(a)                               scanf("%lld",&a)
#define sL2(a,b)                            sL(a) , sL(b)
#define sL3(a,b,c)                          sL(a), sL(b), sL(c)
#define sL4(a,b,c,d)                        sL(a), sL(b), sL(c), sL(d)

#define pI(a)                               printf("%d",a)
#define pI2(a,b)                            pI(a) , pI(b)
#define pI3(a,b,c)                          pI(a), pI(b), pI(c)
#define pI4(a,b,c,d)                        pI(a), pI(b), pI(c), pI(d)

#define pL(a)                               printf("%lld",a)
#define pL2(a,b)                            pL(a) , pL(b)
#define pL3(a,b,c)                          pL(a), pL(b), pL(c)
#define pL4(a,b,c,d)                        pL(a), pL(b), pL(c), pL(d)

/**----------------------Scan and print end--------------------------**/

#define min3(a,b,c)                         min(a,min(b,c))
#define max3(a,b,c)                         max(a,max(b,c))
#define min4(a,b,c,d)                       min(min(a,b),min(c,d))
#define max4(a,b,c,d)                       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)                     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)                     min(min3(a,b,c),min(d,e))

/**----------------------MAX and MIN end-----------------------------**/

#define fst                                 first
#define snd                                 second
#define all(a)                              a.begin(),a.end()
#define rall(a)                             a.rbegin(),a.rend()
#define SQR(a)                              ((a)*(a))
#define Unique(a)                           sort(all(a)),a.erase(unique(all(a)),a.end())
#define Iterator(a)                         __typeof__(a.begin())
#define rIterator(a)                        __typeof__(a.rbegin())
#define FORI(a,it)                          for(Iterator(a) it = a.begin();it != a.end(); it++)
#define RFORI(a,it)                         for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FOR(i, a, b)                        for(int i=(a);i<(b);i++)
#define RFOR(i, b, a)                       for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value)                       memset(A,value,sizeof(A))
#define SZ(V)                               (int)V.size()
#define PB                                  push_back
#define MP                                  make_pair
#define Pi                                  3.14159265358979
#define read(x)                             freopen(x, "r", stdin)
#define write(x)                            freopen(x, "w", stdout)

/**---------------------End of define of all----------------------**/

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

/**-----------------------Directional------------------------------**/

inline int number_of_edges(int degreeofvertices)   {int res; res=(degreeofvertices)/2;return res;};
inline int josephus(int n,int k)                   {if(n==1){return 1;}else{return (josephus(n-1,k)+k-1)%n+1;}}

/**-----------------------Normal equations-------------------------**/

inline int binary_src(int a[],int n,int k)         {int lo=0,hi=n-1,mid;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]==k){return mid+1;}else if(a[mid]>k){hi=mid-1;}else if(a[mid]<k){lo=mid+1;}}return -1;}
inline bool isLeap(lli y)                          {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }
inline int chToIn(char a)                          {int b;b = a-'0';return b;}
inline char inTOch(int a)                          {char b;b= a+'0';return b;}
inline int stToIn(string a)                        {int b;b=atoi(a.c_str());return b;}
inline string appendChar(string s,char a)          {s.append(1,a);return s;}
inline string rev(string a)                        {int siz=SZ(a);string res="";RFOR(i,siz,0){res+=a[i];}return res;}
inline int gcd(int a, int b)                       {return (b == 0 ? a : gcd(b, a % b));}
inline int lcm(int a, int b)                       {return (a * (b / gcd(a, b))); }
vll factors_n; inline lli factor_find_n(lli n)     {for(lli i=2; i<=n; i++)while(n%i==0){n/=i; factors_n.PB(i);}}
vll factors_sqr; inline lli factor_find_sqrt(lli n){for(lli i=2; i*i<=n; i++)while(n%i==0){n/=i; factors_sqr.PB(i);}}
inline lli bigmod(lli a,lli b,lli m)               {if(b==0)return 1%m;lli x=bigmod(a,b/2,m);x=(x*x)%m;if(b%2==1){x=(x*a)%m;}return x;}
inline lli phi(lli n)                              {lli ret=n;for(lli i=2; i*i<=n; i++){if(n%i==0){while(n%i==0)n/=i;}ret-=ret/i;}if(n>1){ret-=ret/n;}return ret;}

/**---------------------End of functions--------------------------**/

int main(){
    lli n,k;
    sL2(n,k);
    lli sm=0;
    lli mn=INF*2;
    lli a[n+10];
    FOR(i,0,n){
        sL(a[i]);
        mn=min(a[i],mn);
    }
    lli res;
    FOR(i,0,n){
        if(a[i]%k==0&&a[i]!=k){
            sm+=abs(mn-a[i]);
        }
        else{
            res=-1;
            pL(res);
            return 0;
        }
    }
    res=sm/k;
    pL(res);

    return 0;
}


/***************************************************DarkdreamOFmy**********************************************************/
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

typedef                                     long int li;
typedef                                     long long int lli;
typedef                                     unsigned long long int ull;
typedef                                     signed long long int sll;
typedef                                     long double lld;
typedef                                     vector<int>vi;
typedef                                     vector<long>vl;
typedef                                     vector<long long int>vll;
typedef                                     vector<double>vd;
typedef                                     vector<long double>vld;
typedef                                     vector<char>vc;
typedef                                     vector<string>vs;
typedef                                     pair<int,int>pii;
typedef                                     pair<long long,long long>pll;
typedef                                     pair<double,double>pdd;
typedef                                     pair<char,char>pcc;
typedef                                     pair<string,string>pss;
typedef                                     map<int,int>mii;
typedef                                     map<long long,long long>mll;
typedef                                     map<char,char>mcc;
typedef                                     map<string,string>mss;
typedef                                     map<string,int>msi;
typedef                                     map< int,vector<int> >miv;
typedef                                     map<vector<int>,vector<int> >mvvi;
typedef                                     map<string,vector<int> >msv;
typedef                                     set<int>si;
typedef                                     set<string>ss;
typedef                                     set<vector<int> >sv;
typedef                                     queue<int>qi;
typedef                                     queue<long long>qll;
typedef                                     queue<string>qs;
typedef                                     stack<int>stki;
typedef                                     stack<long long>stkll;

/**-------------------END OF typedef------------------------------**/

const int                                   INF  = 1000000000;
const int                                   MAX  = 4007;
const int                                   MAX2 = 1000000;
const int                                   MAXD = 20;
const int                                   BASE = 1000000007;
const int                                   MOD  = 1000000007;
const int                                   psz  = 2000006;

/**-------------------Constant int--------------------------------**/

#define sI(a)                               scanf("%d",&a)
#define sI2(a,b)                            sI(a) , sI(b)
#define sI3(a,b,c)                          sI(a), sI(b), sI(c)
#define sI4(a,b,c,d)                        sI(a), sI(b), sI(c), sI(d)

#define sL(a)                               scanf("%lld",&a)
#define sL2(a,b)                            sL(a) , sL(b)
#define sL3(a,b,c)                          sL(a), sL(b), sL(c)
#define sL4(a,b,c,d)                        sL(a), sL(b), sL(c), sL(d)

#define pI(a)                               printf("%d",a)
#define pI2(a,b)                            pI(a) , pI(b)
#define pI3(a,b,c)                          pI(a), pI(b), pI(c)
#define pI4(a,b,c,d)                        pI(a), pI(b), pI(c), pI(d)

#define pL(a)                               printf("%lld",a)
#define pL2(a,b)                            pL(a) , pL(b)
#define pL3(a,b,c)                          pL(a), pL(b), pL(c)
#define pL4(a,b,c,d)                        pL(a), pL(b), pL(c), pL(d)

/**----------------------Scan and print end--------------------------**/

#define min3(a,b,c)                         min(a,min(b,c))
#define max3(a,b,c)                         max(a,max(b,c))
#define min4(a,b,c,d)                       min(min(a,b),min(c,d))
#define max4(a,b,c,d)                       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)                     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)                     min(min3(a,b,c),min(d,e))

/**----------------------MAX and MIN end-----------------------------**/

#define fst                                 first
#define snd                                 second
#define all(a)                              a.begin(),a.end()
#define rall(a)                             a.rbegin(),a.rend()
#define SQR(a)                              ((a)*(a))
#define Unique(a)                           sort(all(a)),a.erase(unique(all(a)),a.end())
#define Iterator(a)                         __typeof__(a.begin())
#define rIterator(a)                        __typeof__(a.rbegin())
#define FORI(a,it)                          for(Iterator(a) it = a.begin();it != a.end(); it++)
#define RFORI(a,it)                         for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FOR(i, a, b)                        for(int i=(a);i<(b);i++)
#define RFOR(i, b, a)                       for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value)                       memset(A,value,sizeof(A))
#define SZ(V)                               (int)V.size()
#define PB                                  push_back
#define MP                                  make_pair
#define Pi                                  3.14159265358979
#define read(x)                             freopen(x, "r", stdin)
#define write(x)                            freopen(x, "w", stdout)

/**---------------------End of define of all----------------------**/

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

/**-----------------------Directional------------------------------**/

inline int number_of_edges(int degreeofvertices)   {int res; res=(degreeofvertices)/2;return res;};
inline int josephus(int n,int k)                   {if(n==1){return 1;}else{return (josephus(n-1,k)+k-1)%n+1;}}

/**-----------------------Normal equations-------------------------**/

inline int binary_src(int a[],int n,int k)         {int lo=0,hi=n-1,mid;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]==k){return mid+1;}else if(a[mid]>k){hi=mid-1;}else if(a[mid]<k){lo=mid+1;}}return -1;}
inline bool isLeap(lli y)                          {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }
inline int chToIn(char a)                          {int b;b = a-'0';return b;}
inline char inTOch(int a)                          {char b;b= a+'0';return b;}
inline int stToIn(string a)                        {int b;b=atoi(a.c_str());return b;}
inline string appendChar(string s,char a)          {s.append(1,a);return s;}
inline string rev(string a)                        {int siz=SZ(a);string res="";RFOR(i,siz,0){res+=a[i];}return res;}
inline int gcd(int a, int b)                       {return (b == 0 ? a : gcd(b, a % b));}
inline int lcm(int a, int b)                       {return (a * (b / gcd(a, b))); }
vll factors_n; inline lli factor_find_n(lli n)     {for(lli i=2; i<=n; i++)while(n%i==0){n/=i; factors_n.PB(i);}}
vll factors_sqr; inline lli factor_find_sqrt(lli n){for(lli i=2; i*i<=n; i++)while(n%i==0){n/=i; factors_sqr.PB(i);}}
inline lli bigmod(lli a,lli b,lli m)               {if(b==0)return 1%m;lli x=bigmod(a,b/2,m);x=(x*x)%m;if(b%2==1){x=(x*a)%m;}return x;}
inline lli phi(lli n)                              {lli ret=n;for(lli i=2; i*i<=n; i++){if(n%i==0){while(n%i==0)n/=i;}ret-=ret/i;}if(n>1){ret-=ret/n;}return ret;}

/**---------------------End of functions--------------------------**/

int main(){
    lli n,k;
    sL2(n,k);
    lli sm=0;
    lli mn=INF*2;
    lli a[n+10];
    FOR(i,0,n){
        sL(a[i]);
    }
    sort(a,a+n);
    lli res;
    FOR(i,1,n){
        if(a[i]%k==0&&a[i]!=k){
            sm+=abs(mn-a[i]);
        }
        else{
            res=-1;
            pL(res);
            return 0;
        }
    }
    res=sm/k;
    pL(res);

    return 0;
}


/***************************************************DarkdreamOFmy**********************************************************/
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

typedef                                     long int li;
typedef                                     long long int lli;
typedef                                     unsigned long long int ull;
typedef                                     signed long long int sll;
typedef                                     long double lld;
typedef                                     vector<int>vi;
typedef                                     vector<long>vl;
typedef                                     vector<long long int>vll;
typedef                                     vector<double>vd;
typedef                                     vector<long double>vld;
typedef                                     vector<char>vc;
typedef                                     vector<string>vs;
typedef                                     pair<int,int>pii;
typedef                                     pair<long long,long long>pll;
typedef                                     pair<double,double>pdd;
typedef                                     pair<char,char>pcc;
typedef                                     pair<string,string>pss;
typedef                                     map<int,int>mii;
typedef                                     map<long long,long long>mll;
typedef                                     map<char,char>mcc;
typedef                                     map<string,string>mss;
typedef                                     map<string,int>msi;
typedef                                     map< int,vector<int> >miv;
typedef                                     map<vector<int>,vector<int> >mvvi;
typedef                                     map<string,vector<int> >msv;
typedef                                     set<int>si;
typedef                                     set<string>ss;
typedef                                     set<vector<int> >sv;
typedef                                     queue<int>qi;
typedef                                     queue<long long>qll;
typedef                                     queue<string>qs;
typedef                                     stack<int>stki;
typedef                                     stack<long long>stkll;

/**-------------------END OF typedef------------------------------**/

const int                                   INF  = 1000000000;
const int                                   MAX  = 4007;
const int                                   MAX2 = 1000000;
const int                                   MAXD = 20;
const int                                   BASE = 1000000007;
const int                                   MOD  = 1000000007;
const int                                   psz  = 2000006;

/**-------------------Constant int--------------------------------**/

#define sI(a)                               scanf("%d",&a)
#define sI2(a,b)                            sI(a) , sI(b)
#define sI3(a,b,c)                          sI(a), sI(b), sI(c)
#define sI4(a,b,c,d)                        sI(a), sI(b), sI(c), sI(d)

#define sL(a)                               scanf("%lld",&a)
#define sL2(a,b)                            sL(a) , sL(b)
#define sL3(a,b,c)                          sL(a), sL(b), sL(c)
#define sL4(a,b,c,d)                        sL(a), sL(b), sL(c), sL(d)

#define pI(a)                               printf("%d",a)
#define pI2(a,b)                            pI(a) , pI(b)
#define pI3(a,b,c)                          pI(a), pI(b), pI(c)
#define pI4(a,b,c,d)                        pI(a), pI(b), pI(c), pI(d)

#define pL(a)                               printf("%lld",a)
#define pL2(a,b)                            pL(a) , pL(b)
#define pL3(a,b,c)                          pL(a), pL(b), pL(c)
#define pL4(a,b,c,d)                        pL(a), pL(b), pL(c), pL(d)

/**----------------------Scan and print end--------------------------**/

#define min3(a,b,c)                         min(a,min(b,c))
#define max3(a,b,c)                         max(a,max(b,c))
#define min4(a,b,c,d)                       min(min(a,b),min(c,d))
#define max4(a,b,c,d)                       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)                     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)                     min(min3(a,b,c),min(d,e))

/**----------------------MAX and MIN end-----------------------------**/

#define fst                                 first
#define snd                                 second
#define all(a)                              a.begin(),a.end()
#define rall(a)                             a.rbegin(),a.rend()
#define SQR(a)                              ((a)*(a))
#define Unique(a)                           sort(all(a)),a.erase(unique(all(a)),a.end())
#define Iterator(a)                         __typeof__(a.begin())
#define rIterator(a)                        __typeof__(a.rbegin())
#define FORI(a,it)                          for(Iterator(a) it = a.begin();it != a.end(); it++)
#define RFORI(a,it)                         for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FOR(i, a, b)                        for(int i=(a);i<(b);i++)
#define RFOR(i, b, a)                       for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value)                       memset(A,value,sizeof(A))
#define SZ(V)                               (int)V.size()
#define PB                                  push_back
#define MP                                  make_pair
#define Pi                                  3.14159265358979
#define read(x)                             freopen(x, "r", stdin)
#define write(x)                            freopen(x, "w", stdout)

/**---------------------End of define of all----------------------**/

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

/**-----------------------Directional------------------------------**/

inline int number_of_edges(int degreeofvertices)   {int res; res=(degreeofvertices)/2;return res;};
inline int josephus(int n,int k)                   {if(n==1){return 1;}else{return (josephus(n-1,k)+k-1)%n+1;}}

/**-----------------------Normal equations-------------------------**/

inline int binary_src(int a[],int n,int k)         {int lo=0,hi=n-1,mid;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]==k){return mid+1;}else if(a[mid]>k){hi=mid-1;}else if(a[mid]<k){lo=mid+1;}}return -1;}
inline bool isLeap(lli y)                          {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }
inline int chToIn(char a)                          {int b;b = a-'0';return b;}
inline char inTOch(int a)                          {char b;b= a+'0';return b;}
inline int stToIn(string a)                        {int b;b=atoi(a.c_str());return b;}
inline string appendChar(string s,char a)          {s.append(1,a);return s;}
inline string rev(string a)                        {int siz=SZ(a);string res="";RFOR(i,siz,0){res+=a[i];}return res;}
inline int gcd(int a, int b)                       {return (b == 0 ? a : gcd(b, a % b));}
inline int lcm(int a, int b)                       {return (a * (b / gcd(a, b))); }
vll factors_n; inline lli factor_find_n(lli n)     {for(lli i=2; i<=n; i++)while(n%i==0){n/=i; factors_n.PB(i);}}
vll factors_sqr; inline lli factor_find_sqrt(lli n){for(lli i=2; i*i<=n; i++)while(n%i==0){n/=i; factors_sqr.PB(i);}}
inline lli bigmod(lli a,lli b,lli m)               {if(b==0)return 1%m;lli x=bigmod(a,b/2,m);x=(x*x)%m;if(b%2==1){x=(x*a)%m;}return x;}
inline lli phi(lli n)                              {lli ret=n;for(lli i=2; i*i<=n; i++){if(n%i==0){while(n%i==0)n/=i;}ret-=ret/i;}if(n>1){ret-=ret/n;}return ret;}

/**---------------------End of functions--------------------------**/

int main(){
    lli n,k;
    sL2(n,k);
    lli sum=0;
    lli mn=INF*2+500000;
    lli a[n+10];
    FOR(i,0,n){
        sL(a[i]);
        mn=min(a[i],mn);
    }
    FOR(i,0,n){
        sum+=abs(mn-a[i]);
    }
    lli res=sum/k;
    if(sum%k==0){
        pL(res);
    }
    else{
        res=-1;
        pL(res);
    }
    return 0;
}


/***************************************************DarkdreamOFmy**********************************************************/
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

typedef                                     long int li;
typedef                                     long long int lli;
typedef                                     unsigned long long int ull;
typedef                                     signed long long int sll;
typedef                                     long double lld;
typedef                                     vector<int>vi;
typedef                                     vector<long>vl;
typedef                                     vector<long long int>vll;
typedef                                     vector<double>vd;
typedef                                     vector<long double>vld;
typedef                                     vector<char>vc;
typedef                                     vector<string>vs;
typedef                                     pair<int,int>pii;
typedef                                     pair<long long,long long>pll;
typedef                                     pair<double,double>pdd;
typedef                                     pair<char,char>pcc;
typedef                                     pair<string,string>pss;
typedef                                     map<int,int>mii;
typedef                                     map<long long,long long>mll;
typedef                                     map<char,char>mcc;
typedef                                     map<string,string>mss;
typedef                                     map<string,int>msi;
typedef                                     map< int,vector<int> >miv;
typedef                                     map<vector<int>,vector<int> >mvvi;
typedef                                     map<string,vector<int> >msv;
typedef                                     set<int>si;
typedef                                     set<string>ss;
typedef                                     set<vector<int> >sv;
typedef                                     queue<int>qi;
typedef                                     queue<long long>qll;
typedef                                     queue<string>qs;
typedef                                     stack<int>stki;
typedef                                     stack<long long>stkll;

/**-------------------END OF typedef------------------------------**/

const int                                   INF  = 1000000000;
const int                                   MAX  = 4007;
const int                                   MAX2 = 1000000;
const int                                   MAXD = 20;
const int                                   BASE = 1000000007;
const int                                   MOD  = 1000000007;
const int                                   psz  = 2000006;

/**-------------------Constant int--------------------------------**/

#define sI(a)                               scanf("%d",&a)
#define sI2(a,b)                            sI(a) , sI(b)
#define sI3(a,b,c)                          sI(a), sI(b), sI(c)
#define sI4(a,b,c,d)                        sI(a), sI(b), sI(c), sI(d)

#define sL(a)                               scanf("%lld",&a)
#define sL2(a,b)                            sL(a) , sL(b)
#define sL3(a,b,c)                          sL(a), sL(b), sL(c)
#define sL4(a,b,c,d)                        sL(a), sL(b), sL(c), sL(d)

#define pI(a)                               printf("%d",a)
#define pI2(a,b)                            pI(a) , pI(b)
#define pI3(a,b,c)                          pI(a), pI(b), pI(c)
#define pI4(a,b,c,d)                        pI(a), pI(b), pI(c), pI(d)

#define pL(a)                               printf("%lld",a)
#define pL2(a,b)                            pL(a) , pL(b)
#define pL3(a,b,c)                          pL(a), pL(b), pL(c)
#define pL4(a,b,c,d)                        pL(a), pL(b), pL(c), pL(d)

/**----------------------Scan and print end--------------------------**/

#define min3(a,b,c)                         min(a,min(b,c))
#define max3(a,b,c)                         max(a,max(b,c))
#define min4(a,b,c,d)                       min(min(a,b),min(c,d))
#define max4(a,b,c,d)                       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)                     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)                     min(min3(a,b,c),min(d,e))

/**----------------------MAX and MIN end-----------------------------**/

#define fst                                 first
#define snd                                 second
#define all(a)                              a.begin(),a.end()
#define rall(a)                             a.rbegin(),a.rend()
#define SQR(a)                              ((a)*(a))
#define Unique(a)                           sort(all(a)),a.erase(unique(all(a)),a.end())
#define Iterator(a)                         __typeof__(a.begin())
#define rIterator(a)                        __typeof__(a.rbegin())
#define FORI(a,it)                          for(Iterator(a) it = a.begin();it != a.end(); it++)
#define RFORI(a,it)                         for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FOR(i, a, b)                        for(int i=(a);i<(b);i++)
#define RFOR(i, b, a)                       for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value)                       memset(A,value,sizeof(A))
#define SZ(V)                               (int)V.size()
#define PB                                  push_back
#define MP                                  make_pair
#define Pi                                  3.14159265358979
#define read(x)                             freopen(x, "r", stdin)
#define write(x)                            freopen(x, "w", stdout)

/**---------------------End of define of all----------------------**/

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

/**-----------------------Directional------------------------------**/

inline int number_of_edges(int degreeofvertices)   {int res; res=(degreeofvertices)/2;return res;};
inline int josephus(int n,int k)                   {if(n==1){return 1;}else{return (josephus(n-1,k)+k-1)%n+1;}}

/**-----------------------Normal equations-------------------------**/

inline int binary_src(int a[],int n,int k)         {int lo=0,hi=n-1,mid;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]==k){return mid+1;}else if(a[mid]>k){hi=mid-1;}else if(a[mid]<k){lo=mid+1;}}return -1;}
inline bool isLeap(lli y)                          {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }
inline int chToIn(char a)                          {int b;b = a-'0';return b;}
inline char inTOch(int a)                          {char b;b= a+'0';return b;}
inline int stToIn(string a)                        {int b;b=atoi(a.c_str());return b;}
inline string appendChar(string s,char a)          {s.append(1,a);return s;}
inline string rev(string a)                        {int siz=SZ(a);string res="";RFOR(i,siz,0){res+=a[i];}return res;}
inline int gcd(int a, int b)                       {return (b == 0 ? a : gcd(b, a % b));}
inline int lcm(int a, int b)                       {return (a * (b / gcd(a, b))); }
vll factors_n; inline lli factor_find_n(lli n)     {for(lli i=2; i<=n; i++)while(n%i==0){n/=i; factors_n.PB(i);}}
vll factors_sqr; inline lli factor_find_sqrt(lli n){for(lli i=2; i*i<=n; i++)while(n%i==0){n/=i; factors_sqr.PB(i);}}
inline lli bigmod(lli a,lli b,lli m)               {if(b==0)return 1%m;lli x=bigmod(a,b/2,m);x=(x*x)%m;if(b%2==1){x=(x*a)%m;}return x;}
inline lli phi(lli n)                              {lli ret=n;for(lli i=2; i*i<=n; i++){if(n%i==0){while(n%i==0)n/=i;}ret-=ret/i;}if(n>1){ret-=ret/n;}return ret;}

/**---------------------End of functions--------------------------**/

int main(){
    lli n,k;
    sL2(n,k);
    lli sm=0;
    lli mn=INF*2;
    lli a[n+10];
    FOR(i,0,n){
        sL(a[i]);
        mn=min(a[i],mn);
    }
    lli res;
    FOR(i,0,n){
        if(a[i]%k==0){
            sm+=abs(mn-a[i]);
        }
        else{
            res=-1;
            pL(res);
            return 0;
        }
    }
    res=sm/k;
    pL(res);

    return 0;
}


/***************************************************DarkdreamOFmy**********************************************************/
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <assert.h>
#include <time.h>
#include <fstream>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

typedef                                     long int li;
typedef                                     long long int lli;
typedef                                     unsigned long long int ull;
typedef                                     signed long long int sll;
typedef                                     long double lld;
typedef                                     vector<int>vi;
typedef                                     vector<long>vl;
typedef                                     vector<long long int>vll;
typedef                                     vector<double>vd;
typedef                                     vector<long double>vld;
typedef                                     vector<char>vc;
typedef                                     vector<string>vs;
typedef                                     pair<int,int>pii;
typedef                                     pair<long long,long long>pll;
typedef                                     pair<double,double>pdd;
typedef                                     pair<char,char>pcc;
typedef                                     pair<string,string>pss;
typedef                                     map<int,int>mii;
typedef                                     map<long long,long long>mll;
typedef                                     map<char,char>mcc;
typedef                                     map<string,string>mss;
typedef                                     map<string,int>msi;
typedef                                     map< int,vector<int> >miv;
typedef                                     map<vector<int>,vector<int> >mvvi;
typedef                                     map<string,vector<int> >msv;
typedef                                     set<int>si;
typedef                                     set<string>ss;
typedef                                     set<vector<int> >sv;
typedef                                     queue<int>qi;
typedef                                     queue<long long>qll;
typedef                                     queue<string>qs;
typedef                                     stack<int>stki;
typedef                                     stack<long long>stkll;

/**-------------------END OF typedef------------------------------**/

const int                                   INF  = 1000000000;
const int                                   MAX  = 4007;
const int                                   MAX2 = 1000000;
const int                                   MAXD = 20;
const int                                   BASE = 1000000007;
const int                                   MOD  = 1000000007;
const int                                   psz  = 2000006;

/**-------------------Constant int--------------------------------**/

#define sI(a)                               scanf("%d",&a)
#define sI2(a,b)                            sI(a) , sI(b)
#define sI3(a,b,c)                          sI(a), sI(b), sI(c)
#define sI4(a,b,c,d)                        sI(a), sI(b), sI(c), sI(d)

#define sL(a)                               scanf("%lld",&a)
#define sL2(a,b)                            sL(a) , sL(b)
#define sL3(a,b,c)                          sL(a), sL(b), sL(c)
#define sL4(a,b,c,d)                        sL(a), sL(b), sL(c), sL(d)

#define pI(a)                               printf("%d",a)
#define pI2(a,b)                            pI(a) , pI(b)
#define pI3(a,b,c)                          pI(a), pI(b), pI(c)
#define pI4(a,b,c,d)                        pI(a), pI(b), pI(c), pI(d)

#define pL(a)                               printf("%lld",a)
#define pL2(a,b)                            pL(a) , pL(b)
#define pL3(a,b,c)                          pL(a), pL(b), pL(c)
#define pL4(a,b,c,d)                        pL(a), pL(b), pL(c), pL(d)

/**----------------------Scan and print end--------------------------**/

#define min3(a,b,c)                         min(a,min(b,c))
#define max3(a,b,c)                         max(a,max(b,c))
#define min4(a,b,c,d)                       min(min(a,b),min(c,d))
#define max4(a,b,c,d)                       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)                     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)                     min(min3(a,b,c),min(d,e))

/**----------------------MAX and MIN end-----------------------------**/

#define fst                                 first
#define snd                                 second
#define all(a)                              a.begin(),a.end()
#define rall(a)                             a.rbegin(),a.rend()
#define SQR(a)                              ((a)*(a))
#define Unique(a)                           sort(all(a)),a.erase(unique(all(a)),a.end())
#define Iterator(a)                         __typeof__(a.begin())
#define rIterator(a)                        __typeof__(a.rbegin())
#define FORI(a,it)                          for(Iterator(a) it = a.begin();it != a.end(); it++)
#define RFORI(a,it)                         for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define FOR(i, a, b)                        for(int i=(a);i<(b);i++)
#define RFOR(i, b, a)                       for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value)                       memset(A,value,sizeof(A))
#define SZ(V)                               (int)V.size()
#define PB                                  push_back
#define MP                                  make_pair
#define Pi                                  3.14159265358979
#define read(x)                             freopen(x, "r", stdin)
#define write(x)                            freopen(x, "w", stdout)

/**---------------------End of define of all----------------------**/

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};

int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

/**-----------------------Directional------------------------------**/

inline int number_of_edges(int degreeofvertices)   {int res; res=(degreeofvertices)/2;return res;};
inline int josephus(int n,int k)                   {if(n==1){return 1;}else{return (josephus(n-1,k)+k-1)%n+1;}}

/**-----------------------Normal equations-------------------------**/

inline int binary_src(int a[],int n,int k)         {int lo=0,hi=n-1,mid;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]==k){return mid+1;}else if(a[mid]>k){hi=mid-1;}else if(a[mid]<k){lo=mid+1;}}return -1;}
inline bool isLeap(lli y)                          {return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); }
inline int chToIn(char a)                          {int b;b = a-'0';return b;}
inline char inTOch(int a)                          {char b;b= a+'0';return b;}
inline int stToIn(string a)                        {int b;b=atoi(a.c_str());return b;}
inline string appendChar(string s,char a)          {s.append(1,a);return s;}
inline string rev(string a)                        {int siz=SZ(a);string res="";RFOR(i,siz,0){res+=a[i];}return res;}
inline int gcd(int a, int b)                       {return (b == 0 ? a : gcd(b, a % b));}
inline int lcm(int a, int b)                       {return (a * (b / gcd(a, b))); }
vll factors_n; inline lli factor_find_n(lli n)     {for(lli i=2; i<=n; i++)while(n%i==0){n/=i; factors_n.PB(i);}}
vll factors_sqr; inline lli factor_find_sqrt(lli n){for(lli i=2; i*i<=n; i++)while(n%i==0){n/=i; factors_sqr.PB(i);}}
inline lli bigmod(lli a,lli b,lli m)               {if(b==0)return 1%m;lli x=bigmod(a,b/2,m);x=(x*x)%m;if(b%2==1){x=(x*a)%m;}return x;}
inline lli phi(lli n)                              {lli ret=n;for(lli i=2; i*i<=n; i++){if(n%i==0){while(n%i==0)n/=i;}ret-=ret/i;}if(n>1){ret-=ret/n;}return ret;}

/**---------------------End of functions--------------------------**/

int main(){
    lli n,k;
    sL2(n,k);
    lli sm=0;
    lli mn=INF*2;
    lli a[n+10];
    FOR(i,0,n){
        sL(a[i]);
    }
    sort(a,a+n);
    lli res;
    FOR(i,1,n){
        if(a[i]%k==0&&a[i]!=k){
            sm+=abs(a[0]-a[i]);
        }
        else{
            res=-1;
            pL(res);
            return 0;
        }
    }
    res=sm/k;
    pL(res);

    return 0;
}