n,m = map(int,input().split())
ans = []
for i in range(n):
    ans.append('0')
for i in range(m):
    s,c = map(int,input().split())
    c = str(c)
    if ans[s-1] == '0' or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()
tmp = ''
for idx,i in enumerate(ans):
    if idx == 0 and i == '0':
        print(-1)
        exit()
    tmp += i
print(int(tmp) if int(tmp) > 0 else -1)