# coding: utf-8

N, M = map(int, input().split())

num = [-1] * (N + 1)
fin = 0
for _ in range(M):
    s, c = map(int, input().split())
    if num[s] == -1:
        num[s] = c
    elif num[s] != c:
        fin = 1
        print(-1)
        break
if N == 1 and sum[1] == 0:
    print(0)
    fin = 1
if fin == 0:
    for i in range(1, N + 1):
        if i == 1:
            if num[i] == -1:
                print(1, end="")
            elif num[i] == 0:
                print(-1)
                break
            else:
                print(num[i], end="")
        else:
            if num[i] == -1:
                print(0, end="")
            else:
                print(num[i], end="")