#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    cin>>n>>k;
    
    int town[n][n];
    vector<int> v(n-1);
    for(int i=0;i<n-1;i++) v[i] = i+1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
           cin>>town[i][j];
        }
    }
    int p = 0; 
    int ans = 0;
    int cnt = 0;
    do{
       for(int n:v){
          ans += town[p][n]; 
          p = n;
       }
       ans += town[p][0];
       if(ans == k) cnt++;
       ans = 0;
       p = 0;
    }while(next_permutation(v.begin(), v.end()));
    
    cout<<cnt<<endl;
}

#include <bits/stdc++.h>
#define st first
#define nd second
#define PQ priority_queue

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 3e5 + 10;
const int MOD = 0;

int a[N];

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i =1; i <= n;i ++){
		int x;
		scanf("%d", &x);
		a[x] ++;
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++){
		k = min(k, a[i]);
		ans += k;
	}
	printf("%lld", ans);

}