n, m = map(int, input().split())
b = []
for _ in range(m):
    b.append(list(map(int, input().split())))
if m == 0:
    if n == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()
for x in range(10**(n-1), 10**n):
    flag = True
    for s, c in b:
        if x % (10**(n-s+1)) // (10**(n-s)) != c:
            flag = False
    if flag:
        print(x)
        exit()
print(-1)
