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

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

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