#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int>> con(m);
  int s, c;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    con.at(i) = make_tuple(s, c);
  }
  sort(con.begin(), con.end());
  vector<int> num(4, -1);
  bool a = true;
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    if (num.at(get<0>(con.at(i))) != -1 &&
        num.at(get<0>(con.at(i))) != get<1>(con.at(i)))
      a = false;
    if (get<0>(con.at(i)) == 1 && get<1>(con.at(i)) == 0) a = false;
    num.at(get<0>(con.at(i))) = get<1>(con.at(i));
  }
  int t = 1;
  for (int i = 0; i < (int)(n); i++) t *= 10;
  if (a) {
    for (int i = 1; i <= n; i++) {
      t /= 10;
      if (num.at(i) == -1) {
        if (i == 1)
          num.at(i) = 1;
        else
          num.at(i) = 0;
      }
      ans += num.at(i) * t;
    }
    cout << ans << endl;
  } else
    cout << -1 << endl;
  return 0;
}
