#include <iostream>
#include <set>
using namespace std;
set<int> distictSet;
int field[28][28], dh[5] = {0, 1, 0, -1, 0}, dw[5] = {0, 0, 1, 0, -1};
void input()
{
for (int h = 1; h <= 5; h++)
{
for (int w = 1; w <= 5; w++)
{
scanf("%d", &field[h][w]);
}
}
}
void dfs(int h, int w, int step, int num)
{
num = num * 10 + field[h][w];
if (step == 6)
{
distictSet.insert(num);
return;
}
for (int i = 1; i <= 4; i++)
{
int nh = h + dh[i], nw = w + dw[i];
if (nh < 1 || nh > 5 || nw < 1 || nw > 5)
{
continue;
}
dfs(nh, nw, step + 1, num);
}
}
void solve()
{
for (int h = 1; h <= 5; h++)
{
for (int w = 1; w <= 5; w++)
{
dfs(h, w, 1, 1);
}
}
}
int main()
{
input();
solve();
printf("%d\n", distictSet.size());
return 0;
}