#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int nm = 0;
  vector<int> ss(n, 1);
  for (int i = 0; i < m; i++) {
    if (ss.at(s.at(i) - 1) == 1) {
      nm += c.at(i) * pow(10, n - s.at(i));
      ss.at(i) = 0;
    }
  }
  bool fct = true;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i != j && s.at(i) == s.at(j) && c.at(i) != c.at(j)) fct = false;
    }
  }
  for (int i = 0; i < m; i++) {
    if (s.at(i) == 1 && c.at(i) == 0) fct = false;
  }
  if (find(s.begin(), s.end(), 1) == s.end()) {
    nm += pow(10, n - 1);
  }
  if (fct)
    cout << nm << endl;
  else
    cout << -1 << endl;
}
