#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  int i;
  for (i = 0; i < m; i++) cin >> s.at(i) >> c.at(i);
  vector<pair<int, int>> sc(m);
  bool ok = true;
  for (i = 0; i < m; i++) sc[i] = make_pair(s.at(i), c.at(i));
  sort(sc.begin(), sc.end());
  for (i = 1; i < m; i++) {
    if (sc.at(i - 1).first == sc.at(i).first &&
        sc.at(i - 1).second != sc.at(i).second)
      ok = false;
  }
  if (!ok)
    cout << -1 << endl;
  else {
    vector<int> num(n, 0);
    for (i = 0; i < m; i++) {
      num.at(s.at(i) - 1) = c.at(i);
    }
    if (num.at(0) == 0) {
      cout << -1 << endl;
    } else {
      bool non0 = false;
      for (i = 0; i < n; i++) {
        if (non0)
          cout << num.at(i);
        else if (num.at(i) != 0) {
          cout << num.at(i);
          non0 = true;
        }
      }
      if (!non0) cout << 0;
      cout << endl;
    }
  }
}
