#include <cstdio>
long long a[100001];
int main()
{
long long n,k,minn,f,ans;
scanf("%I64d%I64d",&n,&k);
minn=1000000001;
for(long long i=0;i<n;i++)
{
scanf("%I64d",&a[i]);
if(a[i]<minn)
minn=a[i];
}
ans=0;
f=0;
for(long long i=0;i<n;i++)
if((a[i]-minn)%k!=0)
{
f=1;
break;
}
else ans+=(a[i]-minn)/k;
if(f)
printf("-1\n");
else printf("%I64d\n",ans);
return 0;
}