N, M = [int(i) for i in input().split()]
s = [0] * M
c = [0] * M
for i in range(N):
  s[i], c[i] = map(int, input().split())

ans = 1000
for i in range(1000):
  S = str(i)
  if len(S) != N:
    continue
  
  is_ok = True
  for j in range(N):
    if S[s[j]] != c[j]:
      is_ok = False
      
  if is_ok:
    ans = min(ans, i)

if ans == 1000:
  print(-1)
else:
  print(ans)
