# -*- coding:utf-8 -*-
n, m = map(int, input().split())
s = []
c = []
flag = 0
for i in range(m):
    si, ci = map(int, input().split())
    s.append(si)
    c.append(ci)

num = 10 ** (n - 1) if n != 1 else 0

while num < 10 ** n:
    for i in range(m):
        if int(str(num)[s[i] - 1]) != c[i]:
            break
        if i == m - 1:
            flag = 1
            break
    if flag == 1:
        break

    num += 1

print(num) if flag==1 else print(-1)
