N,M = map(int,input().split())
ans = []
mark = []
for _ in range(N):
    ans.append(0)
    mark.append(0)
for _ in range(M):
    s,c = map(int,input().split())
    if s == 1 and c == 0:
        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 ans[0] == 0 and N != 1:
    print(-1)
    exit()
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)