import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False

def main():
  n,m = ints()
  dig = [None]*(n);flg = False
  for _ in range(m):
    s,c=ints()
    if dig[s-1]==None:
      dig[s-1]=c
    elif dig[s-1]!=c:
      flg = True
  if flg or (n!=1and dig[0]==0):
    print(-1)
  else:
    num=0
    for i in range(n):
      if i==0 and dig[0]==None:
        dig[0]=1
      elif dig[i]==None:
        dig[i]=0
      num += dig[i]*10**(n-1-i)
    print(num)
      
if __name__ == '__main__':
  main()