n, m = map(int, input().split())
d = dict()
for i in range(m):
    s, c = map(int, input().split())
    if s==1 and c==0:
        print("-1")
        exit()
    if s in d.keys() and d[s] != c:
        print("-1")
        exit()
    d[s] = c
if d[2] == 0 and 1 not in d.keys():
    print("-1")
    exit()
target = 0
for s, c in d.items():
    target += 10**(n-s)*c
print(target)