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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

import java.io.*;
import java.util.*;
import java.util.function.Consumer;

public class Solution {


    static MyScanner sc;
    private static PrintWriter out;
    static long M2 = 1_000_000_000L + 7;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();

        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }

        out = new PrintWriter(new OutputStreamWriter(System.out));

        initData();
        solve();
        out.flush();
    }

    private static void initData() {

    }


    private static void solve() throws IOException {
        int n = sc.nextInt();
        int[][] zz = new int[n][];
        for (int k = 0; k < n; k++) {
            zz[k] = sc.na(6);
        }
        boolean[] res = new boolean[1001];
        for (int[] r : zz) {
            for (int k : r) {
                res[k] = true;
            }
        }
        if (n == 2) {
            xx(zz[0], zz[1], res);
        }
        if (n == 3) {
            xx(zz[0], zz[1], res);
            xx(zz[1], zz[2], res);
            xx(zz[2], zz[0], res);

            xx(zz[0], zz[1], zz[2], res);
            xx(zz[0], zz[2], zz[1], res);
            xx(zz[1], zz[2], zz[0], res);
            xx(zz[1], zz[0], zz[2], res);
            xx(zz[2], zz[0], zz[1], res);
            xx(zz[2], zz[1], zz[0], res);
        }
        for (int i = 1 ; i <= 1000 ; i++) {
            if (!res[i]) {
                out.println(i - 1);
                return;
            }
        }
    }

    private static void xx(int[] zz, int[] zz1, int[] zz2, boolean[] res) {
        for (int t : zz)
            for (int k : zz1)
                for (int k1 : zz2) {
                    res[t * 100 + k * 10 + k1] = true;
                }
    }

    private static void xx(int[] z1, int[] z2, boolean[] res) {
        for (int t1 : z1)
            for (int t2 : z2) {
                res[t1 * 10 + t2] = true;
                res[t2 * 10 + t1] = true;
            }
    }

    private static final class LogTreePar {

        private final int[] levels;
        private final int[][] parents;

        public LogTreePar(int n) {
            levels = new int[n];
            parents = new int[n][19];
            Arrays.fill(levels, -1);
            for (int[] x : parents) {
                Arrays.fill(x, -1);
            }
        }

        public boolean ispar(int f, int l) {
            if (levels[f] >= levels[l]) return false;
            int diff = levels[l] - levels[f];
            return up(l, diff) == f;
        }

        private int up(int item, int diff) {
            int r = 0;
            while (diff > 0 && item >= 0) {
                if (isset(diff, r)) {
                    diff ^= 1 << r;
                    item = parents[item][r];
                }
                r++;
            }
            return item;
        }


        public void add(int item, int parent) {
            parents[item][0] = parent;
            clt(item);
        }


        protected void clt(int item) {
            levels[item] = levels[parents[item][0]] + 1;
            for (int l = 1; l < 19; l++) {
                if (parents[item][l - 1] == -1) break;
                parents[item][l] = parents[parents[item][l - 1]][l - 1];
            }
        }

        public int lca(int f, int l) {
            if (levels[f] > levels[l]) {
                return lca(l, f);
            }
            return lca1(f, up(l, levels[l] - levels[f]));
        }

        private int lca1(int f1, int f2) {
            for (int r = 18; r >= 0 && f1 != f2; r--) {
                if (parents[f1][r] != parents[f2][r]) {
                    f1 = parents[f1][r];
                    f2 = parents[f2][r];
                }
            }
            return f1 == f2 ? f1 : parents[f1][0];
        }
    }


    private static class P {
        private boolean b;
        private final int ind;
        private final int parent;

        public P(int i, boolean b, int par) {
            this.ind = i;
            this.b = b;
            this.parent = par;

        }
    }

    private static void dfs(int start, int[][] neig, Consumer<int[]> onAdd, Consumer<int[]> onRemove) {
        ArrayList<P> toVisit = new ArrayList<P>(3000);
        toVisit.add(new P(start, true, -1));
        boolean[] vis = new boolean[neig.length];
        vis[start] = true;
        int[] level = new int[neig.length];
        while (toVisit.size() > 0) {
            P ppr = toVisit.remove(toVisit.size() - 1);
            if (!ppr.b) {
                onRemove.accept(new int[]{ppr.ind, level[ppr.ind], ppr.parent});
                continue;
            }
            ppr.b = false;
            int i = ppr.ind;
            toVisit.add(ppr);
            onAdd.accept(new int[]{ppr.ind, level[ppr.ind], ppr.parent});
            for (int kk : neig[i]) {
                if (!vis[kk]) {
                    vis[kk] = true;
                    level[kk] = level[i] + 1;
                    toVisit.add(new P(kk, true, i));
                }
            }
        }


    }


    private static int[][] tr(int n) {
        int[][] x = new int[2][n - 1];
        for (int i = 0; i < n - 1; i++) {
            x[0][i] = sc.nextInt() - 1;
            x[1][i] = sc.nextInt() - 1;
        }
        return pn(x, n);
    }

    private static int[][] pn(int[][] x, int n) {
        int[] ct = new int[n];
        int[][] res = new int[n][];
        for (int v : x[0]) {
            ct[v]++;
        }
        for (int v : x[1]) {
            ct[v]++;
        }
        for (int l = 0; l < n; l++) {
            res[l] = new int[ct[l]];
        }
        for (int i = 0; i < x[0].length; i++) {
            res[x[0][i]][--ct[x[0][i]]] = x[1][i];
            res[x[1][i]][--ct[x[1][i]]] = x[0][i];
        }
        return res;
    }


    private static boolean isset(long i, int k) {
        return (i & (1 << k)) > 0;
    }

    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }


    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }


}