n,m = map(int,input().split())
ans = [-1]*n
for _ in range(m):
    s,c = map(int,input().split())
    if ans[s-1]!=-1 and ans[s-1]!=c:
        print(-1)
        exit()
    if ans[s-1]==-1:
        ans[s-1] = c
    else:
        continue
ret = ''
for a in ans:
    if a==-1:
        ret += '0'
    else:
        ret += str(a)
print(ret if not set(ret)=={'0'} else -1)
