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8 6 4
 3
2 3 4 5 6 7
3 4 5 6 7 8
9 1 2 3 4 5
 2
0 1 2 3 4 5
4 5 6 7 8 9
 3
2 7 3 6 4 5
0 2 1 9 4 8
8 6 9 5 4 0
 2
0 1 2 3 4 5
6 7 8 9 6 6
 2
1 7 2 0 4 3
5 2 3 6 1 0
 1
6 2 8 5 1 3
 3
5 4 8 1 6 7
0 9 3 5 8 6
2 4 7 8 1 3
 1
6 3 1 9 4 9
 3
0 1 9 1 0 8
9 9 3 5 6 2
9 3 9 9 7 3
 3
8 1 6 8 6 8
7 0 2 5 8 4
5 2 0 3 1 9
 3
2 0 1 3 4 5
6 7 8 9 1 1
3 4 5 6 6 7
 3
4 4 5 0 6 6
7 1 6 9 5 4
5 0 4 0 3 9
 2
0 1 2 3 4 5
9 8 7 6 5 4
 2
0 2 9 1 8 5
0 7 4 3 2 5
 2
2 3 9 1 6 7
2 5 4 3 0 6
 2
5 7 4 2 1 9
2 2 7 1 1 8
 1
3 9 1 7 4 5
 3
7 7 2 5 3 2
3 0 0 6 4 4
1 2 1 1 9 1
 1
7 9 5 0 4 6
 3
7 1 3 0 2 4
2 4 3 0 9 5
1 9 8 0 6 5
 1
4 3 8 9 2 3

3
 9
 9
 4
 2
 10
 10
 1
 4
 0
 2
 5
 0
 8
 2
 2
 10
 19
 3
 3
 2
 0
 5
 19
 3
 2
 1
 2
 1
 4
 2
 9
 5
 8
 1
 10
 7
 0
 5
 4
 3
 5
 9
 9
 29
 0
 0
 1
 8
 9
 21
 6
 21
 1
 8
 6
 1
 21
 6
 3
 2
 0
 0
 1
 0
 0
 0
 2
 0
 3
 0
 98
 2
 9
 9
 10
 9
 7
 3
 21
 1
 3
 32
 19
 1
 9
 5
 7
 2
 1
 7
 0
 65
 0

//package Mura;
/*****   BY MURAD   ******/
/*Everyone has a different way of thinking, so God Created us*/
/*Hope You Respect My Way..,Thank You*/
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Code {
    public static int max(int a, int b)
    {
        return (a > b)? a : b;
    }
    static class DPS {
        void print(int a[][])
        {
            for(int i=0;i<a.length;i++)
            {
                for(int j=0;j<a[0].length;j++)
                {
                    System.out.print(a[i][j]+" ");
                }
                System.out.println();
            }
        }
        int lcs( char[] X, char[] Y, int m, int n )
        {
            int L[][] = new int[m+1][n+1];
            for (int i=0; i<=m; i++)
            {
                for (int j=0; j<=n; j++)
                {
                    if (i == 0 || j == 0) {
                        L[i][j] = 0;
                        continue;
                    }
                    else if (X[i-1] == Y[j-1])
                        L[i][j] = L[i-1][j-1] + 1;
                    else
                        L[i][j] = max(L[i-1][j], L[i][j-1]);
                }
            }
            return L[m][n];
        }
        String LongestSubPlindrome(String s) {
            int len = s.length();
            if (s == null || len < 2)
                return s;
            boolean table[][] = new boolean[len][len];
            int left = 0, right = 0;
            for (int i = 1; i < len; i++) {
                for (int j = 0; j < i; j++) {
                    boolean isplindrome = table[i - 1][j + 1] || i - j <= 2;
                    if (s.charAt(i) == s.charAt(j) && isplindrome) {
                        table[i][j] = true;
                        if (i - j > right - left) {
                            left = j;
                            right = i;
                        }
                    }
                }
            }
            return s.substring(left, right + 1);
        }
        int knp(int []wt,int []val,int n,int W)
        {
            int i, w;
            int K[][] = new int[n+1][W+1];

            // Build table K[][] in bottom up manner
            for (i = 0; i <= n; i++)
            {
                for (w = 0; w <= W; w++)
                {
                    if (i==0 || w==0)
                        K[i][w] = 0;
                    else if (wt[i-1] <= w)
                        K[i][w] = Math.max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
                    else
                        K[i][w] = K[i-1][w];
                }
            }

            return K[n][W];
        }
        int cutRod(int price[],int n)
        {
            int val[] = new int[n+1];
            val[0] = 0;
            // Build the table val[] in bottom up manner and return
            // the last entry from the table
            for (int i = 1; i<=n; i++)
            {
                int max_val = Integer.MIN_VALUE;
                for (int j = 0; j < i; j++)
                    max_val = Math.max(max_val,
                            price[j] + val[i-j-1]);
                val[i] = max_val;
            }
            return val[n];
        }
        int LIS(int []a,int n)
        {
            int dp[]=new int[n+1];
            dp[0]=1;
            for(int i=1;i<n;i++)
            {
                int maxval=Integer.MIN_VALUE;
                for(int j=0;j<i;j++)
                {
                    if(a[i]>a[j])
                    {
                        dp[i]=dp[i-1]+1;
                    }
                    else
                    {
                        dp[i]=dp[i-1];
                    }
                }
            }
            return dp[n-1];
        }
        int edit_dist(char[]x,char[]y,int xl,int yl)
        {
            int dp[][]=new int[xl+1][yl+1];
            for(int i=0;i<=xl;i++)
            {
                for(int j=0;j<=yl;j++)
                {
                    if (i==0) {
                        dp[i][j] = j;
                        continue;
                    }
                    if (j==0) {
                        dp[i][j] = i;
                        continue;
                    }
                    if(x[i-1]==y[j-1])
                    {
                        dp[i][j]=dp[i-1][j-1];
                    }
                    else
                        dp[i][j]=1+Math.min(dp[i][j-1],Math.min(dp[i-1][j],dp[i-1][j-1]));
                }
            }
            return dp[xl][yl];
        }
    }
    static class DC{
        void insertion_sort(int []a,int left,int right)
        {
            int n = left + right;
            for (int i = left + 1; i <= right; ++i)
            {
                int key = a[i];
                int j = i - 1;
                while (j >= 0 && a[j] > key)
                {
                    a[j + 1] = a[j];
                    j = j - 1;
                }
                a[j + 1] = key;
            }
        }

        void merg(int []arr,int low,int mid,int hig)
        {
            int nleft=mid-low+1;
            int nright=hig-mid;
            int left[]=new int[nleft];
            int []right=new int[nright];
            for(int i=0;i<nleft;i++)
                left[i]=arr[i+low];
            for(int j=0;j<nright;j++)
                right[j]=arr[j+mid+1];
            int i=0,j=0;
            int k=low;
            while (i<nleft&&j<nright)
            {
                if(left[i]<=right[j])
                {
                    arr[k]=left[i];
                    i++;
                }
                else
                {
                    arr[k]=right[j];
                    j++;
                }
                k++;
            }
            while(i<nleft)
            {
                arr[k]=left[i];
                i++;
                k++;
            }
            while(j<nright)
            {
                arr[k]=right[j];
                j++;
                k++;
            }
        }
        void sort_merg(int []a,int low,int hig){
            if(low<hig)
            {
                int mid=(low+hig)/2;
                sort_merg(a,low,mid);
                sort_merg(a,mid+1,hig);
                merg(a,low,mid,hig);
            }
        }
        int findKthLargest(int[] nums, int k) {
            int start = 0, end = nums.length - 1, index = nums.length - k;
            while (start < end) {
                int pivot = partion(nums, start, end);
                if (pivot < index) start = pivot + 1;
                else if (pivot > index) end = pivot - 1;
                else return nums[pivot];
            }
            return nums[start];
        }
        int partion(int[] nums, int start, int end) {
            int pivot = start, temp;
            while (start <= end) {
                while (start <= end && nums[start] <= nums[pivot]) {
                    start++;
                }
                while (start <= end && nums[end] > nums[pivot]) {
                    end--;
                }
                if (start > end) break;
                temp = nums[start];
                nums[start] = nums[end];
                nums[end] = temp;
            }
            temp = nums[end];
            nums[end] = nums[pivot];
            nums[pivot] = temp;
            return end;
        }
        int kth_smallest(int a[],int low,int hig,int k)
        {
            if(k<=low+hig)
            {
                int pos=partition_qs(a,low,hig);
                if(pos==k)
                    return a[pos];
                if(pos>k)
                    return kth_smallest(a,low,pos-1,k);
                return kth_smallest(a,pos+1,hig,k);
            }
            return 0;
        }
        int partition_qs(int a[],int low,int hig){
            int i=low-1;
            int j=low;
            int piv=a[hig];
            for(j=low;j<hig;j++)
            {
                if(a[j]<=piv)
                {
                    i++;
                    int temp=a[i];
                    a[i]=a[j];
                    a[j]=temp;
                }
            }
            int temp=a[i+1];
            a[i+1]=piv;
            a[hig]=temp;
            return i+1;
        }
        void sort(int a[],int low,int hig)
        {
            if(low<hig)
            {
                int p1=partition_qs(a,low,hig);
                sort(a,low,p1-1);
                sort(a,p1+1,hig);
            }
        }
    }
    public static long mod=998244353;
    public static boolean isPowerOfTwo(int n)
    {
        if (n == 0)
            return false;
        while (n != 1)
        {
            if (n % 2 != 0)
                return false;
            n = n / 2;
        }
        return true;
    }
    public static long GCD(long x,long y){
        if(y==0)
            return x;
        else
            return GCD(y,x%y);
    }
    static class Graph {
        private int v;
        private ArrayList<Integer> adj[];
        Graph(int vv) {
            v = vv;
            adj = new ArrayList[v];
            for (int i = 0; i < v; ++i) {
                adj[i] = new ArrayList<>();
            }
        }
        void addEdge(int v, int w) {
            adj[v].add(w);
            adj[w].add(v);
        }
    }
    public static void main(String[] args)throws IOException {
        Scanner inp = new Scanner(System.in);
       // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //StringTokenizer st = new StringTokenizer(br.readLine());
        boolean flag=false;
        int n=inp.nextInt();
        int [][]cube=new int[n][6];
        boolean []vis=new boolean[100];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<6;j++)
                cube[i][j]=inp.nextInt();
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<cube[0].length;j++)
                vis[cube[i][j]]=true;
        }
        n--;
        int z=0,v=0;
        while (n==2&&v<6) {
            for(int i=1;i<6&&v<6;i++)
            {
                int val=cube[z][v];
                for(int j=0;j<6;j++)
                {
                    vis[10*val+cube[i][j]]=true;
                    vis[10*cube[i][j]+val]=true;
                }
                v++;
                i=0;
            }
        }
        n--;
        z=v=0;
        while(n==1&&v<6)
        {
            flag=true;
            for(int i=2;i<6&&v<6;i++)
            {
                int val=cube[z][v];
                for(int j=0;j<6;j++)
                {
                    vis[10*val+cube[i][j]]=true;
                    vis[10*cube[i][j]+val]=true;
                }
                v++;
                i=1;
            }
        }
        if(flag)
        {
            z=1;
            v=0;
            for(int i=2;i<6&&v<6;i++)
            {
                int val=cube[z][v];
                for(int j=0;j<6;j++)
                {
                    vis[10*val+cube[i][j]]=true;
                    vis[10*cube[i][j]+val]=true;
                }
                v++;
                i=1;
            }
        }
        for(int i=1;i<vis.length;i++) {
            if(vis[i]==false)
            {
                System.out.println(i-1);
                return;
            }
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
    static class Pair implements Comparable<Pair> {
        int value, idx;
        Pair(int v, int i)
        {
            value = v;
            idx = i;
        }
        @Override
        public int compareTo(Pair p) {
            return value - p.value;
        }
    }
    public static int[] bctsort(int[] array, int bucketCount) {
        if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
        if (array.length <= 1) return array;
        int high = array[0];
        int low = array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i] > high) high = array[i];

            if (array[i] < low) low = array[i];
        }
        double interval = ((double)(high - low + 1))/bucketCount;
        ArrayList<Integer> buckets[] = new ArrayList[bucketCount];
        for (int i = 0; i < bucketCount; i++) {

            buckets[i] = new ArrayList();

        }
        for (int i = 0; i < array.length; i++) {

            buckets[(int)((array[i] - low)/interval)].add(array[i]);
        }
        int pointer = 0;

        for (int i = 0; i < buckets.length; i++) {

            Collections.sort(buckets[i]);

            for (int j = 0; j < buckets[i].size(); j++) {

                array[pointer] = buckets[i].get(j);

                pointer++;

            }
        }
        return array;
    }
    /*
      int maxValueInMap=(Collections.max(mp.values()));  // This will return max value in the Hashmap
        for (Map.Entry<String, Integer> entry : mp.entrySet()) {  // Itrate through hashmap
            if (entry.getValue()==maxValueInMap) {
                System.out.println(entry.getKey());
                break;
            }
        }
        Relatively Prime :- if diffrence between two number is equal to 1
    */
}