import numpy as np

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

l = [list(map(int, input().split())) for _ in range(m)]
x = np.array(l)

answer = 0
if n > 1:
    if [1,0] in x:
        answer = -1
    print(answer)

if len(np.unique(x[:,0])) != len(x[:,0]):
    if len(np.unique(x, axis=0)) == len(x):
        answer = -1
        print(answer)
    else:
        ans = np.zeros((n), int)
        for i in range(m):
            ans[x[i, 0] - 1] = x[i, 1]

if len(np.unique(x[:,0])) == len(x[:,0]):
    ans = np.zeros((n), int)
    for i in range(m):
        ans[x[i,0]-1] = x[i,1]

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