# A = [list(map(int, input().split())) for _ in range(3)]
# n = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
n, m = map(int, input().split())
S = []
C = []
for i in range(m):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
ans = [0, 0, 0]
for i in range(m):
    ans[S[i]-1] = C[i]
if ans[2] == 0:
    print(-1)
    exit()
elif n == 2 and ans[1] == 0:
    print(-1)
    exit()
if n == 3:
    print("".join(map(str, ans[:n])))
elif n == 2:
    print("".join(map(str, ans[1:3])))
elif n == 1:
    print("".join(map(str, ans[2])))
