N, M = map(int, input().split())
num = ['0'] * N
error = False

for i in range(M):
    s, c = map(int, input().split())
    if not int(num[s-1]) in [0, c]:
        error = True
        break
    else:
        num[s-1] = str(c)

if num[0] == '0' or error:
    print(-1)
else:
    print(''.join(num))
