#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  bool f = true;
  for (int i = 0; i < m; i++) {
    if (v[i].first == 1 && v[i].second == 0) {
      f = false;
      break;
    }
    if (i != m - 1 && m > 1) {
      if (v[i].first == v[i + 1].first && v[i].second != v[i + 1].second) {
        f = false;
        break;
      }
    }
  }
  if (f) {
    vector<int> w(n, 0);
    for (int i = 0; i < m; i++) {
      if (v[i].first == 1) {
        w[0] = v[i].second * pow(10, n - 1);
      } else if (v[i].first == 2) {
        w[1] = v[i].second * pow(10, n - 2);
      } else {
        w[2] = v[i].second;
      }
    }
    if (w[0] == 0) {
      w[0] = pow(10, n - 1);
    }
    cout << w[0] + w[1] + w[2] << endl;
  } else {
    cout << -1 << endl;
  }
}
