def solve():
    nlist, mlist = [], []
    n, m = map(int, input().split())
    for _ in range(m):
        nn, mm = map(int, input().split())
        nlist.append(nn)
        mlist.append(mm)

    res = ["0"] * n
    res[0] = "1"
    done = [False] * (n+1)

    for si, ci in zip(nlist, mlist):
        if not done[si-1]:
            res[si-1] = str(ci)
        else:
            if res[si-1] != str(ci):
                print(-1)
                return

        done[si-1] = True

    r = int("".join(res))

    if len(str(r)) == n:
        print(r)
    else:
        print(-1)

solve()
