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

num = [[] for i in range(n)]

for i in range(m):
    s,c = map(int, input().split())
    num[s-1].append(c)

ans = [0]*n

for i in range(n):
    q = list(set(num[i]))
    if len(q) == 1:
        ans[i] = q[0]
    elif len(q) == 0:
        ans[i] = 0
    else:
        ans[0] = -1

if n == 1:
    print(*ans,sep='')
elif ans[0] == -1 or ans[0] == 0:
    print(-1)
else:
    print(*ans,sep='')

