#include<bits/stdc++.h>
using namespace std;
int a[10], n;
int ten[] = {1, 10, 100, 1000, 10000, 11, 110, 1100, 11000};
bool check(int x, int y) {
int z = 0, a, b;
int cnt = 0;
z = abs(x - y);
for (int i = 0; i < 5; i++) {
a = x % 10, b = y % 10;
x /= 10, y /= 10;
if(a != b) cnt += ten[i];
if(z % 10 == 0) z /= 10;
}
bool ok = true;
for(int i = 0; i < 9; i++) if(ten[i] != cnt) ok = false;
if(!ok) return false;
if(z > 0 && cnt == 1) return true;
if(z > 99) return false;
return z % 11 == 0;
}
bool check(int x) {
for (int i = 0; i < n; i++) {
if(!check(a[i], x)) return false;
}
return true;
}
int getIn() {
int res = 0, t;
for (int i = 0; i < 5; i++) {
scanf("%d",&t);
res = res * 10 + t;
}
return res;
}
int main() {
scanf("%d",&n);
for (int i = 0; i < n; i++) {
a[i] = getIn();
}
int ans = 0;
for (int i = 0; i < 100000; i++) {
if(check(i)) {
printf("%05d\n",i);
ans++;
}
}
printf("%d",ans);
return 0;
}