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

x = [0]*5

flag = False
nn = 0

cnt = 0
for _ in range(m):
    s,c = map(int,input().split())
    s-=1
    if x[s] != 0 and x[s] != c:
        flag = True
    else:
        x[s] = c

    nn = max(nn,s)
    

ans = 0

z = 0
for i in x:
    if i == 0:
        z+=1


if z == len(x):
    flag = True

n = max(x)
for i in range(nn+1):
    ans +=10**(nn-i)*x[i]

if flag:print(-1)
else: print(ans)

