#C

n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(m)]
s = [l[i][0] for i in range(m)]
c = [l[i][1] for i in range(m)]
t = [0] * n

    
for i in range(m):
    if t[s[i]-1] == 0 or t[s[i]-1] == c[i]:
        t[s[i]-1] = c[i]
    else:
        print("-1")
        break
else:
    #print(t)
    if t[0] == 0 and n != 1:
        print("-1")
    else:
        print(t[0]*100 + t[1]*10 + t[2])