n, m = list(map(lambda x: int(x), input().split()))

ans = ["0"] * n

for i in range(m):
    s, c = list(map(lambda x: int(x), input().split()))
    if int(ans[s - 1]) == 0:
        ans[s - 1] = str(c)
    elif c < int(ans[s - 1]) and c != 0:
        ans[s - 1] = str(c)

if ans[0] == '0':
    print('-1')
else:
    print(''.join(ans))