import sys
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)
    
for x in range(10**(N-1), 10**N):
    ans = 0
    st = str(x)
    for i in range(M):
        if int(st[s[i]]) == c[i]:
            ans += 1
    if ans==M:
        print(x)
        sys.exit()
print(-1)