import sys

n,m = map(int,input().split())
if m == 0:
    print('-1')
    sys.exit()
a = []
wk =[]
kai = 0
for i in range(m):
    wk = (list(map(int,input().split())))
    if wk in a:
        m -= 1
    else:
        a.append(wk)

a.sort()

if a[0][1] == 0:
        print('-1')
        sys.exit()
for i in range(m):
    if a[i][1]==n and a[i][1]==0:
        print('-1')
        sys.exit()
for i in range(m-1):
    if a[i][0] == a[i+1][0]:
        print('-1')
        sys.exit()

for i in range(m):
    kai += (10**(n-a[i][0]))*a[i][1]

print(kai)