#C - Guess The Number https://atcoder.jp/contests/abc157/tasks/abc157_c
x,m = map(int, input().split())
s=[-1]*m
c=[-1]*m
num = [-1]*3
ans = 0
for i in range(m):
    s[i], c[i] = map(int, input().split())

for j, l in zip(s, c):
    if num[j-1] == -1:
        num[j-1] = l
    elif num[j-1] != l:
        print(-1)
        break

    #num[j-1]とlが同じときは何もされない
else:
    num = list(map(lambda x: x*0 if x<0 else x, num))
    for k in num:
        ans = ans *10 + k
    if ans != 0 and num>1:
        print(ans)
    else:
        print(-1)