n, m = list(map(int, input().split()))
X = [-1] * n
flag = False
for _ in range(m):
    s, c = list(map(int, input().split()))
    i = s - 1
    if i == 0:
        if c == 0:
            if n > 1:
                flag = True
            else:
                X[i] = c
        else:
            X[i] = c
    else:
        if X[i] != -1:
            if X[i] != c:
                flag = True
            else:
                X[i] = c
        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]))