import numpy as np

n,m = map(int,input().split())

sc = []
num = [0]*n
flag = 0
for i in range(m):
    sc.append(list(map(int,input().split())))
    num[sc[i][0]-1] = sc[i][1]
    if sc[i][0] == 1 and sc[i][1] == 0:
            flag = -1
    for j in range(i):
        if sc[i][0] == sc[j][0] and sc[i][1] != sc[j][1]:
            flag = -1

if flag != -1:
    ans = 0
    for i in range(n):
        ans += num[i]*(10**(n-i-1))
    print(ans)
else:
    print(flag)
