N, M = map(int,input().split())
v = []
for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    v.append((x,y))

for i in range(10**N):
    s = str(i)
    if len(s) != N:
        continue
    if all(s[a] == str(b) for a,b in v):
        print(i)
        exit()
print(-1)