n,m = map(int,input().split())
num = [0]*n
flag = 1
ss = []
for i in range(m):
    s,c = map(int,input().split())
    s -= 1
    if c == 0:
        ss.append(s)
    if (s in ss and num[s] != c) or (s == 0 and c == 0):
        print(-1)
        flag = 0
        break
    num[s] = c
if flag:
    if num[0] == 0:
        num[0] = 1
    num = ''.join([str(num) for num in num])
    print(num)