# ABC 157 C
n,m=map(int,input().split())
l=[[] for i in range(n)]
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if not c in l[s]:
        l[s].append(c)
for i in range(n):
    if not l[i]:
        l[i].append(0)

for ll in l:
    if len(ll)>1:
        print(-1)
        exit()
ans=10001

for i in range(1000):
    t_str=str(i)
    ok=True
    if len(t_str)!=n:
        continue
    for j in range(n):
        # print(t_str[j:j+1])
        # print(l[j][0])
        if int(t_str[j:j+1])!=l[j][0]:
            ok=False
            break
    if ok:
        ans=min(ans,i)
if ans==10001:
    print(-1)
    exit()
print(ans)