# 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]*3
check=[0]*3
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()

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)