n,m=map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]

ans = ['0']*(m+1)
for i in range(len(sc)):
    if ans[sc[i][0]] == '0' or ans[sc[i][0]] >= str(sc[i][1]):
        ans[sc[i][0]] = str(sc[i][1])
    else:
        continue
if ans[1] == '0':
    print(-1)
else:
    print(int(''.join(ans)))