#include <cstdio>
#include <algorithm>
using namespace std;

int a[10][10], b[5];
int cale() {
	int i = a[0][b[4]];
	for (int k = 3; k >= 1; k--)
		i = a[i][b[k]];
	return i;
}
int cal() {
	return a[cale()][b[0]];
}
bool detected(int x) {
	for (int i = 1; i < 5; i++) {
		b[i] = x % 10;
		x /= 10;
	}
	b[0] = cale();
	for (int i = 0; i < 4; i++) {
		if (b[i] != b[i + 1]) {
			swap(b[i], b[i + 1]);
			if (cal() == 0)
				return false;
			swap(b[i], b[i + 1]);
		}
	}
	for (int i = 0; i < 5; i++) {
		int tmp = b[i];
		for (int j = 0; j < 10; j++) {
			if (j == tmp) continue;
			b[i] = j;
			if (cal() == 0)
				return false;
		}
		b[i] = tmp;
	}
	return true;
}
int main(void) {
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			scanf("%d", &a[i][j]);
	int sum = 0;
	for (int i = 0; i < 10000; i++)
		if (!detected(i))
			sum++;
	printf("%d\n", sum);
}
