N, M = map(int, input().split())
lis = [0]*N
S = []
C = []
ERROR = False
for _ in range(N):
  s,c = map(int, input().split())
  S.append(s)
  C.append(c)
for i in range(len(S)-1):
  for j in range(i+1,len(S)):
    if S[i] == S[j] and C[i] != C[j]:
      ERROR = True
if ERROR:
  print('-1')
else:
  output = ''
  for i in range(len(S)):
    lis[S[i]-1] = C[i]
  for i in range(N):
    output += str(lis[i])
  if lis[0] == '0':
    print('-1')
  else:
    print(output)