N, M = map(int, input().split())
S = []
C = []
for _ in range(N):
  s, c = map(int, input().split())
  S.append(s - 1)
  C.append(c)

num = ['*'] * N

for s, c in zip(S, C):
  if num[s] == '*':
    num[s] = str(c)
  elif num[s] != str(c):
    print(-1)
    exit()

print(''.join(num).replace('*', '0'))