import numpy as np

N, M = map(int, input().split())
s = [list(map(int, input().split())) for i in range(M)]

s = np.array(s)
bool1 = 0
for i in range(M):
  bool1 += (s[i,0]==1)*(s[i,1]==0)

bool2 = 1
for i in range(N):
  ss = s[(s[:,0] == i), 1]
  if ss.shape[0]>1:
      for i in range(ss.shape[0]):
          bool2 *= (ss[i]==ss[0])

if bool1 > 0:
  ans = -1
elif bool2 == 0:
  ans = -1
else:
  A = 0
  for i in range(N):
    if s[(s[:,0] == i+1), 1].shape[0] == 0:
      if i == 0:
        A += 10**(N-1)
    else:
      A += s[(s[:,0] == i+1), 1][0] * 10**(N-1-i)
  ans = A

print(int(ans))