#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> occ;
  bool bad = 0;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (occ.count(s) && occ[s] != c) {
      bad = 1;
      break;
    } else if (s == 1 && c == 0) {
      bad = 1;
      break;
    } else {
      occ[s] = c;
    }
  }
  if (!occ.count(1)) {
    bad = 1;
  }
  if (bad) {
    cout << -1 << endl;
  } else {
    int p = 1;
    while (p <= n) {
      if (occ.count(p)) {
        cout << occ[p];
      } else {
        cout << "0";
      }
      p++;
    }
    cout << "\n";
  }
}
