import sys
n, m = map(int, input().split())
num = []
s = []
c = []
ans = 0
keta = 1
list = [False,False,False,False,False]
for i in range(m):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)



for i in range(n):
    num.append(0)
if(n>1):
    num[0] = 1

for i in range(m):
    if(list[s[i]-1] and not num[s[i]-1] == c[i]):
        print(-1)
        sys.exit()
    num[s[i]-1] = c[i]
    if(num[0] == 0):
        print(-1)
        sys.exit()
    list[s[i]-1] = True


for i in num[::-1]:
    ans = ans + i*keta
    keta = keta * 10

print(ans)
