N,M = map(int,input().split())
if N == 1:
    ans = [0]
else:
    ans = [1]
mark = [0]

for _ in range(N-1):
    ans.append(0)
    mark.append(0)

for _ in range(M):
    s,c = map(int,input().split())
    if s == 1 and c == 0 and N != 1:
        print(-1)
        exit()
    elif mark[s-1] == 1 and ans[s-1] != c:
        print(-1)
        exit()
    else:
        ans[s-1] = c
        mark[s-1] = 1
if N == 1:
    a = ans[0]
if N == 2:
    a = ans[0] * 10 + ans[1]
if N == 3:
    a = ans[0] * 100 + ans[1] ** 10 + ans[2]
print(a)