N, M = map(int, input().split())
s = []
c = []
for i in range(M):
    si, ci = map(int, input().split())
    s.append(si-1)
    c.append(ci)

answer = [0] * N
valid = True
for i in range(M):
    if answer[s[i]] != 0 and answer[s[i]] != c[i]:
        valid = False
        break
    answer[s[i]] = c[i]
if answer[0] == 0:
    valid = False
if valid:
    print(int(''.join(map(lambda x: str(x), answer))))
else:
    print(-1)