#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n,m;
  cin >> n >> m;
  int a[n];
  for(int i = 0;i<n;i++) a[i] = 10
  int f = 0;
  for(int i = 0;i < m;i++)
  {
     int b,c;
     cin >> b >> c;
     if(a[b-1] > 9) a[b-1] = c;
     else if(a[b-1] != c)
     {
         f = 1;
         break;
     }
     else a[b-1] = c;
  }
  for(int i = 0;i < n;i++)
  {
      if(a[i] > 9) a[i] = 0;
  }
  if(f == 1) cout << -1 << endl;
  else
  {
      for(int i = 0;i<n;i++) cout <<a[i];
      cout << "\n";
  }
  return 0;
}
