#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#define inf 0x3f3f3f3f
#define esp 1e-7
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int r[11][11];

void divide(int num,int &a,int &b,int &c,int &d){
	a=num/1000;
	b=(num%1000)/100;
	c=(num%100)/10;
	d=num%10;
}


int main(){
	for (int i=0;i<10;i++){
		for (int j=0;j<10;j++){
			r[i][j]=read();
		}
	}
	int ans=0;
	for (int i=0;i<=9999;i++){
		int tmp,a,b,c,d;
		divide(i,a,b,c,d);
		tmp=r[r[r[r[0][a]][b]][c]][d];
		if ((a!=b&&tmp==r[r[r[r[0][b]][a]][c]][d])
		  ||(b!=c&&tmp==r[r[r[r[0][a]][c]][b]][d])
		  ||(c!=d&&tmp==r[r[r[r[0][a]][b]][d]][c])
		  ||(d!=tmp&&d==r[r[r[r[0][a]][b]][c]][tmp]))
		ans++;
		else{
			for (int j=0;j<=9;j++){
				if 		(j!=a&&tmp==r[r[r[r[0][j]][b]][c]][d]) {ans++;break;}
				else if (j!=b&&tmp==r[r[r[r[0][a]][j]][c]][d]) {ans++;break;}
				else if (j!=c&&tmp==r[r[r[r[0][a]][b]][j]][d]) {ans++;break;}
				else if (j!=d&&tmp==r[r[r[r[0][a]][b]][c]][j]) {ans++;break;}
				else if (j!=tmp&&j==r[r[r[r[0][a]][b]][c]][d]) {ans++;break;}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}