N, M = (int(x) for x in input().split())
lst = [None] * N
for _ in range(M):
    s, c = (int(x) for x in input().split())
    if lst[s-1] is None:
        lst[s-1] = c
    elif lst[s-1] != c:
        print(-1)
        break
else:
    if lst[0] == 0:
        print(-1)
    else:
        if lst[0] is None:
            lst[0] = 1
        num = 0
        for i in range(N):
            if lst[i] is None: continue
            num += lst[i] * 10 ** (N - i - 1)
        print(num)