n,m = map(int,input().split())
s=[]
c=[]
ans = []
for i in range(m):
    si,ci = map(int,input().split())
    s.append(si)
    c.append(ci)

for i in range(n):
    ans.append(0)
    
chk = ans[:]

for i,v in enumerate(s):
    ans[v-1] = c[i]

if len(ans) != 1 and ans[0] == 0:
    print(-1)
    exit()

for i, v in enumerate(s):
    if ans[v-1] == c[i]:
        chk[v-1] = 0
    else:
        chk[v-1] = 1
    
    
if 1 in chk:
    print(-1)
    exit()


cnt = len(ans)
ans2 = 0
if cnt == 1:
    print(ans[0])
    exit()
elif cnt == 2:
    ans2 = 10 * ans[0] + ans[1]
    print(ans2)
    exit()
elif cnt == 3:
    ans2 = 100 * ans[0] + 10 * ans[1] + ans[2]
    print(ans2)
    exit()