def abc157c(n, m, sc):
    ans = [0 for _ in range(n)]
    if (1,0) in sc:
        return -1
    for s, c in sc:
        if ans[s-1] and ans[s-1]!=c:
            return -1
        else:
            ans[s-1]=c
    if not ans[0]:
        return -1
    _ans = ""
    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))