def solve():
    N, M = map(int,input().split())
    os = None
    ts = None
    hs = None
    for i in range(M):
        s,c = map(int, input().split()) 
        if s == 1:
            if os is None:
                os = c
            elif os != c:
                print(-1)
                return
        elif s ==2:
            if ts is None:
                ts = c
            elif ts != c:
                print(-1)
                return
        elif s ==3:
            if hs is None:
                hs = c
            elif hs != c:
                print(-1)
                return
    if os == 0 and ts is None and hs is None:
        print(-1)
        return
    if ts == 0 and hs is None:
        print(-1)
        return
    if hs == 0:
        print(-1)
        return

    if os is None:
        os = 0
    if ts is None:
        ts = 0
    if hs is None:
        hs = 1
    print(os+ts*10+hs*100)

solve()