# ABC 157 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nms = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
n,m=nm()
l=[0]*9
check=[0]*9
for i in range(m):
    s,c=map(int,input().split())
    s-=1
    if l[s]!=c:
        check[s]+=1
    l[s]=c
# print(l)
ans=[]
if sum(l)==0:
    ans='0'
    if n==1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

for cc in check:
    if cc>1:
        print(-1)
        exit()

# print(l)
# print(check)
for i in range(1000):
    t=(3-len(str(i)))*'0'
    t+=str(i)
    flg=True
    for j,tt in enumerate(t):
        tm=int(tt)
        if tm!=l[j]:
            flg=False
            break
    if flg:
        ans.append(int(t))
if ans:
    print(min(ans))
else:
    print(-1)

# is_zero=True

# for ll in l:
#     if ll==0 and is_zero==True:
#         continue
#     else:
#         is_zero=False
#         ans+=str(ll)

# # print(ans)
# ans2=''
# for i in range(n):
#     ans2+=ans[i]
# print(ans2)