// #includes {{{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; // }}} // pre-written code {{{ #define REP(i,n) for(int i=0;i<(int)(n);++i) #define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i) #define LET(x,a) __typeof(a) x(a) //#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i) #define ALL(c) (c).begin(), (c).end() #define MP make_pair #define EXIST(e,s) ((s).find(e)!=(s).end()) #define REvector(a) memvector((a),0,sizeof(a)) #define vector(a) memvector((a),-1,sizeof(a)) #define PB push_back #define DEC(it,command) __typeof(command) it=command const int INF=0x3f3f3f3f; typedef long long Int; typedef unsigned long long uInt; #ifdef __MINGW32__ typedef double rn; #else typedef long double rn; #endif typedef pair pii; /* #ifdef MYDEBUG #include"debug.h" #include"print.h" #endif */ // }}} int C[222][111][111]; vector > > v; int N,M; vector > make_blist(int s){ vector > bs; REP(i,N){ vector st; REP(j,N)st.push_back(C[s][i][j]); bs.push_back(st); } REP(j,N){ vector st; REP(i,N)st.push_back(C[s][i][j]); bs.push_back(st); } { vector st; REP(i,N)st.push_back(C[s][i][i]); bs.push_back(st); } { vector st; REP(i,N)st.push_back(C[s][i][N-1-i]); bs.push_back(st); } return bs; } int main(){ cin>>N>>M; REP(t,M)REP(i,N)REP(j,N)cin>>C[t][i][j]; REP(t,M){ v.push_back(make_blist(t)); } int ans = INF; REP(t,M)RREP(s,t+1,M){ for(auto a:v[t])for(auto b:v[s]){ vector c = a; c.insert(c.end(),ALL(b)); sort(ALL(c)); int k = distance(c.begin(),unique(ALL(c))); ans = min(k,ans); } } cout<