x = list(map(int,input().split(" ")))
n = x[0]
m = x[1]

s = []
for i in range(m):
    s.append(list(map(int,input().split(" "))))

ng = 0

for i in range(m):
    if s[i][0] == 1 and s[i][1] == 0:
        ng += 1

for i in range(m):
    for j in range(i+1,m):
        if s[i][0] == s[j][0] and s[i][1] != s[j][1]:
            ng += 1

ans_list = []

for i in range(m):
    cal = (10 ** (m-s[i][0])) * s[i][1]
    ans_list.append(cal)

for i in range(m):
    for j in range(i+1,m):
        if ans_list[i] == ans_list[j]:
            ans_list[j] = 0

ans = 0
for i in range(m):
    ans += ans_list[i]

if n == 1 and ans == 0:
    print(ans)
elif ng >= 1:
    print(-1)
else:
    print(ans)