import sys

n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]

sc.sort(key=lambda x:x[0])
sc.sort()
anl =[0 for i in range(n)]
an = 0

if m == 0:
    if n == 1:
        print(0)
        sys.exit()
    else:
        print('-1')
        sys.exit()
if sc[0][1]==0:
    if n>1:
        print('-1')
        sys.exit()
    else:
        print(0)
        sys.exit()

for i in range(m):
    for j in range(1,m):
        if sc[i][0] == sc[j][0] and sc[i][1]!=sc[j][1]:
            print('-1')
            sys.exit()
        else:
            anl[sc[i][0]-1] = sc[i][1]

for i in range(n):
    an += 10**(n-i-1)*anl[i]
print(an)