n, m = map(int, input().split())

ans = [0]*n 
a = 0
for i in range(m):
    s, c = map(int, input().split())
    if ans[s-1] == 0:
        ans[s-1] = c 
    elif not ans[s-1] == c:
        print(-1)
        break
    if i == m-1:
        if ans[0] == 0:
            print(-1)
        else:
            for j in range(n):
                a = a+ans[j]*(10**(n-j-1))
            print(a)