N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
s = [sc[i][0] for i in range(M)]
c = [sc[j][1] for j in range(M)]
box = [0] * M
ans = str()
for m in range(M):
    box[s[m] - 1] = c[m]

for k in box:
    ans += str(k)

if box[0] != 0:
    print(int(ans))
else:
    print(-1)