n, m = list(map(int, input().split()))
X = [-1] * n
flag = False
for _ in range(m):
    s, c = list(map(int, input().split()))
    if c == 0 and s == 1 and n > 1:
        flag = True
    else:
        i = s - 1
        if X[i] != -1 and X[i] != c:
            flag = True
        else:
            X[i] = c
if flag:
    print('-1')
else:
    if X[0] == -1:
        X[0] = 1
    print(''.join([str(max(x, 0)) for x in X]))