N, M = map(int, input().split())
S = list()
C = list()
S_used = list()
for i in range(M):
  s_, c_ = map(int, input().split())
  S.append(s_)
  C.append(c_)
ret = 0
duplist = [x for x in set(S) if S.count(x) > 1]

if len(duplist) > 0:
  for d in duplist:
    index_ = [i for i, x in enumerate(S) if x == d]
    dupnums_ = [C[x] for x in index_]
    if dupnums_.count(dupnums_[0]) != len(dupnums_):
      ret = -1
if ret == 0:
  for i in range(len(S)):
    if S[i] == 1 and C[i] == 0:
      ret = -1
    elif S[i] not in S_used:
      ret +=C[i] * 10 ** (N - S[i])
      S_used.append(S[i])
  if ret >= 0 and ret < 10 ** (N - 1):
    ret += 10 ** (N - 1)
print(ret)