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