#include <iostream>
#include <cstdio>
#include <bitset>
using namespace std;
bitset <100001> bits, tmp;
int n, m;
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
bits.set();
for(int i = 1; i <= n; i++){
tmp.reset();
for(int j = 1; j <= m; j++){
int x;
cin >> x;
tmp.set(x);
}
bits &= tmp;
}
cout << bits.count();
}