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

#define REP(i,m,n) for(int i=(m);i<(n);++i)
#define rep(i,n) REP(i,0,n)

int main(){
    int N;
    cin >> N;
    vector<vector<int>> vs;
    rep(i,N){
      int a,b,c;
      cin >> a >> b >> c;
      vector<int> tmp={a,b,c};
      vs.push_back(tmp);
    }
    long long INF=10000000000000000;
  	long long DP[N][1<<N];
    rep(i,N){
      rep(j,(1<<N)){
        DP[i][j]=INF;
      }
    }
    DP[0][0]=0;
    rep(t,N){
    rep(i,N){
      int a,b,c;
      a=vs[i][0];
      b=vs[i][1];
      c=vs[i][2];
      rep(j,N){
        if(i==j){
          continue;
        }
        int p,q,r;
        p=vs[j][0];
        q=vs[j][1];
        r=vs[j][2];
        int cost1=abs(p-a)+abs(q-b)+max(0,r-c);
        int cost2=abs(a-p)+abs(b-q)+max(0,c-r);
        rep(k,(1<<N)){
          DP[j][k|(1<<i)]=min(DP[j][k|(1<<i)],DP[i][k]+cost1);
        }
        rep(k,(1<<N)){
          DP[i][k|(1<<j)]=min(DP[i][k|(1<<j)],DP[j][k]+cost2);
        }
      }
    }
    }
  
    cout << DP[0][(1<<N)-1] << endl;
  
    return 0;
}
#include<bits/stdc++.h>  
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(int i = a; i <=b; i++)
#define rep2(i,a,b) for(int i = a; i>=b; i--)
#define PB push_back 
#define MP make_pair
#define db long double
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define cases int testcases;cin>>testcases; while(testcases--)
#define INF 2000000000
const double PI = acos(-1);
const int N = 100005;
#define eps 1e-6
#define MOD 1000000007
  int32_t main() 
  {
    IOS



        int n,k,m;
        cin >> n >> k >> m;

       	m*=(n);
        int arr[n];
        int sum = 0;

        for(int i = 1; i <= n-1; i++)
        {
        	cin >> arr[i];
        	sum += arr[i];
        }


        int l = max(0LL,m-sum);
        
        if(l > k)
        {
        	l = -1;
        }


        cout << l;

    return 0;
      }
        