N,M=map(int,input().split())
S=[input().split() for i in range(M)]

a=True
c=True
for j in range(M):
    if c==True:
        for i in range(M):
            if S[i][0]==S[j][0]:
                if S[i][1]!=S[j][1]:
                    print(-1)
                    a=False
                    c=False
                    break

D={}

if a==True:
    for i in range(M):
        D[S[i][0]]=S[i][1]

if N>=2:
    if a==True:
        for j in range(2,N+1):
            for i in range(M):
                if S[i][0]=="1":
                    a1=S[i][1]
                if S[i][0]=="2":
                    a2=S[i][1]
                if S[i][0]=="3":
                    a3=S[i][1]
        for i in range(M):
            if S[i][0]=="1":
                if int(S[i][1])>=1:
                    a1=S[i][1]
                else:
                    print(-1)
                    a=False
                    break

if N==1:
    if a==True:
        for i in range(M):
            if S[i][0]=="1":
                if int(S[i][1])>=1:
                    a1=S[i][1]
                else:
                    print(-1)
                    a=False
                    break

if N==1 and a==True:
    print(a1)

if N==2 and a==True:
    b=False
    if b==False:
        try:
            print(a1,a2,sep="")
            b=True
        except:
            None
        if b==False:
            try:
                print(a1,0,sep="")
                b=True
            except:
                None
            if b==False:
                try:
                    print(1,a2,sep="")
                    b=True
                except:
                    None
                if b==False:
                    print(1,0,sep="")
            


if N==3 and a==True:
    b=False
    if b==False:
        try:
            print(a1,a2,a3,sep="")
            b=True
        except:
            None
        if b==False:
            try:
                print(a1,a2,0,sep="")
                b=True
            except:
                None
            if b==False:
                try:
                    print(a1,0,a3,sep="")
                    b=True
                except:
                    None
                if b==False:
                    try:
                        print(1,a2,a3,sep="")
                        b=True
                    except:
                        None
                    if b==False:
                        try:
                            print(a1,0,0,sep="")
                            b=True
                        except:
                            None
                        if b==False:
                            try:
                                print(1,a2,0,sep="")
                                b=True
                            except:
                                None
                            if b==False:
                                try:
                                    print(1,0,a3,sep="")
                                    b=True
                                except:
                                    None
                                if b==False:
                                    print(1,0,0,sep="")

### FIXED CODE ###

N,M=map(int,input().split())
S=[input().split() for i in range(M)]

a=True
c=True
for j in range(M):
    if c==True:
        for i in range(M):
            if S[i][0]==S[j][0]:
                if S[i][1]!=S[j][1]:
                    print(-1)
                    a=False
                    c=False
                    break

if N>=2:
    if a==True:
        for i in range(M):
            if S[i][0]=="2":
                a2=S[i][1]
            if S[i][0]=="3":
                a3=S[i][1]
        for i in range(M):
            if S[i][0]=="1":
                if int(S[i][1])>=1:
                    a1=S[i][1]
                else:
                    print(-1)
                    a=False
                    break

if N==1:
    if a==True:
        for i in range(M):
            if S[i][0]=="1":
                    a1=S[i][1]

if N==1 and a==True and M!=0:
    print(a1)
if N==1 and a==True and M==0:
    print(0)

if N==2 and a==True:
    b=False
    if b==False:
        try:
            print(a1,a2,sep="")
            b=True
        except:
            None
        if b==False:
            try:
                print(a1,0,sep="")
                b=True
            except:
                None
            if b==False:
                try:
                    print(1,a2,sep="")
                    b=True
                except:
                    None
                if b==False:
                    print(1,0,sep="")
            


if N==3 and a==True:
    b=False
    if b==False:
        try:
            print(a1,a2,a3,sep="")
            b=True
        except:
            None
        if b==False:
            try:
                print(a1,a2,0,sep="")
                b=True
            except:
                None
            if b==False:
                try:
                    print(a1,0,a3,sep="")
                    b=True
                except:
                    None
                if b==False:
                    try:
                        print(1,a2,a3,sep="")
                        b=True
                    except:
                        None
                    if b==False:
                        try:
                            print(a1,0,0,sep="")
                            b=True
                        except:
                            None
                        if b==False:
                            try:
                                print(1,a2,0,sep="")
                                b=True
                            except:
                                None
                            if b==False:
                                try:
                                    print(1,0,a3,sep="")
                                    b=True
                                except:
                                    None
                                if b==False:
                                    print(1,0,0,sep="")