n,m = map(int, input().split())
ans = ['0']*n
aa = {}
for i in range(m):
    s, c = map(int, input().split())
    if s in aa.keys() and aa[s]!=c:
        print(-1)
        exit()
    ans[s-1]=str(c)
    aa[s] = c
ans = int(''.join(ans))
print(-1 if n>=2 and ans==0 else ans)
