#!/usr/bin/env python

from sys import stdin, stderr

INF = 100000
def solve(N, rules):
   res = INF
   for num in xrange(10**N):
      snum = str(num)
      if len(snum) != N:
         continue
      ok = True
      for s, c in rules:
         if ord(snum[s-1])-ord('0') != c:
            ok = False
            break
      if ok:
         res = min(res, num)
   return res if res < INF else -1

def main():
   N, M = map(int, stdin.readline().split())
   rules = []
   for i in xrange(M):
      rules.append( map(int, stdin.readline().split()) )

   res = solve(N, rules)
   print(res)

   return 0

if __name__ == '__main__': main()
