from collections import Counter


n, m = map(int, input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i], c[i] = map(int, input().split())
flg = False
if n == 1:
    c = list(set(c))
    if len(c) > 1:
        print(-1)
    elif len(c) == 1:
        print(c[0])
    else:
        print(0)
else:
    for i in range(10 ** (n-1), 10 ** n):
        for j in range(m):
            if int(str(i)[s[j] - 1]) == c[j]:
                flg = True
            else:
                flg = False
                break
        if flg:
            print(i)
            exit()
    print(-1)
