input1 = list(map(int, (input().split())))

n = input1[0]
m = input1[1]

b = []

for i in range(m):
    b.append(list(map(int, (input().split()))))

# print(b)
a = [-1] * n

for s in b:
    if a[s[0]-1] == -1:
        a[s[0]-1] = s[1]
    elif a[s[0]-1] == s[1]:
        pass
    else:
        print(-1)
        exit(0)
# print(a)

if a[0] == -1:
    a[0] = 1

for i in range(n-1):
    if a[i+1] == -1:
        a[i+1] = 0


res = a[0] * 100 + a[1] * 10 + a[2]
if(res < 10**n and res >= 10**(n-1)):
    print(res)
else:
    print(-1)
