def abc157c(n, m, sc):
    ans = [-1 for _ in range(n)]
    if (1,0) in sc and n!=1:
        return -1
    for s, c in sc:
        if ans[s-1]!=-1 and ans[s-1]!=c:
            return -1
        else:
            ans[s-1]=c
    _ans = ""
    for a in ans:
        if a == -1:
            _ans+='0'
        else:
            _ans+=str(a)
    if _ans[0]==0 and n==1:
        return 0
    return _ans.lstrip('0')
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
print(abc157c(n,m,sc))