n, m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
for i in range(10**(n-1), 10**n):
    j = str(i)
    if all(int(j[s[k][0]-1])==s[k][1] for k in range(m)):
        print(i)
        exit()
print(-1)