import sys

N, M = map(int, sys.stdin.readline().split())

cond = {}
flag = True
for _ in range(M):
    s, c = map(int, sys.stdin.readline().split())
    if s not in cond:
        if s == 1 and c == 0:
            flag = False
            break
        else:
            cond[s] = c
    else:
        if cond[s] != c:
           flag = False
           break

if flag == False:
    print(-1)
else:
    ans = ""
    for i in range(1, 4):
        if i in cond:
            ans += str(cond[i])
        else:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
    print(ans)