# n, m = int(input().split())
n, m = (int(x) for x in input().split())
lst = []
# print(n, m)

for cnt in range(n):
    lst.append(0)


flag = True
for cnt in range(m):
    s, c = (int(x) for x in input().split())
    if ():
        pass
    elif(lst[s - 1] != 0 and lst[s - 1] != c):
        # print('111')
        flag = False
    else:
        lst[s - 1] = c

num = 0

# print(lst)


if(not flag):
    num = -1
elif(len(lst) > 1 and lst[0] == 0):
    # print('aaa')
    num = -1
else:
    n = 10 ** (n - 1)
    for cnt in lst:
        num += cnt * n
        n /= 10


print(int(num))
