n, m = map(int, input().split())
x = [-1]*n
ans = 0
count = 0
for i in range(m):
    s, c = map(int, input().split())
    if (s==1) and (c==0):
        count = 1
    if x[s-1]!=-1 and x[s-1]!=c:
        count = 1
    if x[s-1] != c:
        ans += c*(10**(n-s))
    x[s-1] = c

if count==1:
    print(-1)
elif ans>=10**(n-1):
    print(ans)
else:
    print(ans+10**(n-1))