n, m = map(int, input().split())
if n == 1:
    a = 0
    b = 10
else:
    a = 10**(n-1)
    b = 10**n
ok = []
for i in range(m):
    s, c = map(int, input().split())
    if i == 0:
        for j in range(a,b):
            if str(j)[s-1] == str(c):
                ok.append(j)
    else:
        for j in range(len(ok)):
            if str(ok[j])[s-1] != str(c):
                ok[j] = 1000
ok.sort()
if len(ok) == 0 or ok[0] == 1000:
    print(-1)
else:
    print(ok[0])