#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  bool ng = false;
  map<int, int> s_c;
  for(int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    map<int, int>::iterator it = s_c.find(s);
    if(it == s_c.end()) s_c[s] = c;
    else if(it->second != c) ng = true;
    if((n>1) && (s==1) && (c==0)) ng = true;
  }

  if(ng) {
      cout << -1 << endl;
      return 0;
  }

  char ans[n+1] = {'\0'};
  for(int s = 1; s <= n; ++s) {
      map<int, int>::iterator it = s_c.find(s);
      if(it == s_c.end()) ans[s-1] = ((s==1) ? '1' : '0');
      else ans[s-1] = '0' + it->second;
  }

  cout << stoi(ans) << endl;
  return 0;
}