#初期入力
import sys
N,M = (int(x) for x in input().split())
if N==1 and M==0:
    print(0)
    sys.exit(0)
digit ={str(i):[] for i in range(1,N+1)}

for i in range(M):
    d,n =input().split()
    digit[d].append(n)

ans =""
for i,v in digit.items():
    if i =="1" and v[0] =="0" and (len(v) ==2 or len(v) ==3): #1桁目（一番左）は✖０、最小値「１」
            print(-1)
            sys.exit(0)
    elif len(v) ==2:
        if v[0] !=v[1]: #同じ桁なのに違う値は✖
            print(-1)
            sys.exit(0)
        else:
            ans +=v[0]
    elif len(v) ==3:
        if v[0] !=v[1] or v[2] !=v[1] or v[0] !=v[2]:
            print(-1)
            sys.exit(0)
        else:
            ans +=v[0]
    elif len(v) ==1:
        ans +=v[0]
    elif len(v) ==0:
        if i =="1":
            ans +="1" #1桁目（一番左）は✖０、最小値「１」
        else:
            ans +="0"

print(ans)