#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m,y,z;
  cin >> n >> m;
  vector<int> x(n,0);
  for (int i = 0; i < m; i++) {
    cin >> y >> z;
    if(x[y]==10&&x[y]!=z) {
      cout << -1 << endl;
      exit(0);
    }
    if(z==0) {
      if(y==1){
        cout << -1 << endl;
        exit(0);
      }else{
        z=10;
      }
    }
    x[y]=z;
  }
  if(x[1]%==0) x[1]=1;
  for (int i = 1; i < n+1; i++) {
    cout << x[i]%10;
  }
  cout << endl;
}