console.log((args=>{
  const [[N,M],...tmp] = args.trim().split('\n').map( r=>r.split(' ').map(v=>v|0));
  const a = Array(N).fill(NaN);
  for ( let i = 0; i < M; i++ ) {
    const [s,c] = tmp[i];
    if ( s === 1 && c === 0 ) return '-1';
    if ( isNaN(a[s-1]) ) a[s-1] = c;
    else if ( a[s-1] !== c ) return '-1';
  }
  if ( isNaN(a[0]) ) a[0] = 1;
  return a.map(v=>v|0).join``;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
