n, m = map(int , input().split())
sc = []
for i in range(m):
    s, c = map(int, input().split())
    sc.append([s, c])

sc.sort()

d1 = sc[0][0]
n1 = sc[0][1]
ans = str(n1)
for d, x in sc[1:]:
    print(d1, n1)
    print(d, n)
    if d == d1 and x != n1:
        ans = '-1'
        break
    elif n == n1:
        pass
    elif d - d1 > 0:
        ans += '0' * ((d - d1) - 1)
        ans += str(x)
    d1 = d
    n1 = x
if ans[0] == '0' or len(ans) != n:
    ans = '-1'


print(ans)