n,m = list(map(int,input().split()))
ans = ['0' for i in range (n)]
fl = True

for i in range (m):
    s,c = input().split()
    s = int(s) - 1
    if (s == 0 and c == '0' and N != 1):
        fl = False
    if (ans[s] != '0'):
        if (ans[s] != c):
            fl = False
    else:
        ans[s] = c

res = ''

if (ans[0] == '0' and N != 1):
    ans[0] = '1'

for i in ans:
    res += i

print (res if fl else -1)