N,M = map(int,input().split())
s = [list(map(int,(input().split()))) for i in range(N)]
number = 0
dummy = 0
index = []
for i in range(M):
    for j in range(i+1,M):      #同じ桁の数字に関する言及を排除
        if s[i] == s[j]:
            index.append(i)
        elif s[i][0] == s[j][0] and not s[i][1] == s[j][1]:
            dummy = 1
            break
        elif s[i][0] ==1 and  s[i][1] == 0:
            dummy = 1
            break
for i in index:
    s.pop(i)
for i in range(len(s)):
    number += (10**(N-s[i][0]))*s[i][1]
if dummy >=1:
    print(-1)
else:
    print(number)