#!/usr/bin/env pypy3

def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    mod=10**9+7

    N,M=MI()

    ans=[-1]*N

    f=1

    for i in range(M):

        s,c=MI()

        s-=1

        if ans[s]==-1:

            ans[s]=c

        else:

            if ans[s]==c:

               continue

            else:

                f=0

    if ans[0]==0 and N!=1:

        f=0      

      

    if f==0:

        print((-1))

    elif N==1 and (ans[0]==0 or ans[0]==-1):

        print("0")

        

    else:

        for i in range(N):

            if ans[i]==-1:

                ans[i]=0

                if i==0:

                    ans[i]=1

            

        print((''.join(map(str, ans))))



main()

#!/usr/bin/env pypy3

def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    N,M=MI()

    st=pow(10,N-1)

    en=pow(10,N)

    

    if N==1:

        st=0

   

    s=[0]*M

    c=[0]*M

    for i in range(M):

        s[i],c[i]=MI()

        s[i]-=1

   

    ans=-1



   

    for i in range(st,en):

        flag=1

        i2=str(i)

        

        for j in range(M):

            aaa=int(i2[s[j]])

            if aaa!=c[j]:

                flag=0

                break

               

        if flag:

            ans=i

            break

        

    print(ans)

       

   

main()

#!/usr/bin/env pypy3
def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    mod = 10**9 + 7
    N, M = MI()
    ans = [-1] * N
    f = 1
    for i in range(M):
        s, c = MI()
        s -= 1
        if ans[s] == -1:
            ans[s] = c
        else:
            if ans[s] == c:
                continue
            else:
                f = 0
    if ans[0] == 0 and N != 1:
        f = 0
    if f == 0:
        print((-1))
    elif N == 1 and (ans[0] == 0 or ans[0] == -1):
        print("0")
    else:
        for i in range(N):
            if ans[i] == -1:
                ans[i] = 0
                if i == 0:
                    ans[i] = 1
        print(("".join(map(str, ans))))


main()

#!/usr/bin/env pypy3
def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    N, M = MI()
    st = pow(10, N - 1)
    en = pow(10, N)
    if N == 1:
        st = 0
    s = [0] * M
    c = [0] * M
    for i in range(M):
        s[i], c[i] = MI()
        s[i] -= 1
    ans = -1
    for i in range(st, en):
        flag = 1
        i2 = str(i)
        for j in range(M):
            aaa = int(i2[s[j]])
            if aaa != c[j]:
                flag = 0
                break
        if flag:
            ans = i
            break
    print(ans)


main()

-    mod = 10**9 + 7 -    ans = [-1] * N -    f = 1 +    st = pow(10, N - 1) +    en = pow(10, N) +    if N == 1: +        st = 0 +    s = [0] * M +    c = [0] * M -        s, c = MI() -        s -= 1 -        if ans[s] == -1: -            ans[s] = c -        else: -            if ans[s] == c: -                continue -            else: -                f = 0 -    if ans[0] == 0 and N != 1: -        f = 0 -    if f == 0: -        print((-1)) -    elif N == 1 and (ans[0] == 0 or ans[0] == -1): -        print("0") -    else: -        for i in range(N): -            if ans[i] == -1: -                ans[i] = 0 -                if i == 0: -                    ans[i] = 1 -        print(("".join(map(str, ans)))) +        s[i], c[i] = MI() +        s[i] -= 1 +    ans = -1 +    for i in range(st, en): +        flag = 1 +        i2 = str(i) +        for j in range(M): +            aaa = int(i2[s[j]]) +            if aaa != c[j]: +                flag = 0 +                break +        if flag: +            ans = i +            break +    print(ans)