#include <iostream>
#include <string>
#include <stdlib.h>
#include <bits/stdc++.h>
#define USE_MATH_DEFINES
//dobri pravougaonici
using namespace std;

int main()
{
    long long int n, k, r, b, d, s, s1, d1, p, ms, md, a[100][100];
    int i, j;
    int* v=new int [1000000];
    cin>>n>>k;
    r=0;
    for (i=1; i<=k; i++) {
        v[i]=0;
    }
    for (i=1; i<=n; i++) {
        for (j=1; j<=n; j++) {
           cin>>a[i][j];
           v[a[i][j]]++;
        }
    }
    for (i=1; i<=n; i++) {
        for (j=1; j<=n; j++) {
                b=0;
                d=i;
                s=j;
                s1=0;
                ms=0;
                md=0;
        if (v[a[i][j]]!=0) {
           while (a[d][s]==a[d][s+s1]) {
                if (s1+1>ms) {
                    ms=s1;
                }
                d1=0;
                while (a[d][s]==a[d+d1][s]) {
                if (d1+1>md) {
                    md=d1;
                }
                b=b+1;
                d1=d1+1;
           }
                s1=s1+1;
           }
           if (((md+1)*(ms+1)==b)&&(b==v[a[i][j]])) {
            r=r+1;
           }
           else {v[a[i][j]]=0;}
        }
    }
    }
    cout<<r;

return 0;
}