#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> p[i].first >> p[i].second;
  }
  vector<int> ans(n, -1);
  bool ok = true;
  for (int i = 0; i < (int)(m); i++) {
    if (ans[p[i].first - 1] == -1 || ans[p[i].first - 1] == p[i].second) {
      ans[p[i].first - 1] = p[i].second;
    } else {
      ok = false;
      break;
    }
  }
  if (ok) {
    if (n != 1) {
      if (ans[0] == -1 || ans[0] == 0) {
        ok = false;
      }
    } else if (n == 1) {
      if (ans[0] == -1) ok = false;
    }
  }
  if (ok) {
    for (int i = 0; i < (int)(n); i++) {
      if (ans[i] == -1) ans[i] = 0;
      cout << ans[i];
    }
  } else {
    if (m == 0 && n == 1) {
      cout << 0;
    } else if (m == 0 && n != 1) {
      cout << pow(10, n - 1);
    } else {
      cout << -1;
    }
  }
  cout << "\n";
}
