import numpy as np
import sys

if __name__ == "__main__":
  _n, _m = map(int, input().split())

  if _m == 0:
    ans = 0 if _n == 1 else 10 if _n == 2 else 100
    print(ans)
    sys.exit()

  restrict = np.zeros(_n, dtype=np.bool)
  num = np.full(_n, -1)
  for i in range(_m):
    _s, _c = map(int, input().split())
    if _s == 1 and _c == 0:
      print('-1')
      sys.exit()
    if not restrict[_s-1]:
      restrict[_s-1] = True
      num[_s-1] = _c
    else:
      if not num[_s-1] == _c:
        print('-1')
        sys.exit()

  ans = ""
  for ord,n in enumerate(num):
    if ord == 0 and n == -1:
      ans += str(1)
    elif n == -1:
      ans += str(0)
    else:
      ans += str(n)

  print(int(ans))
