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