#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, i, j, k;
  bool ok = true;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < m; ++i) {
    for (j = i + 1; j < m; j++) {
      if ((s.at(i) == s.at(j)) && (c.at(i) != c.at(j))) {
        ok = false;
        break;
      }
    }
    if ((s.at(i) == 1) && (c.at(i) == 0)) ok = false;
  }
  if (!ok) {
    cout << -1 << endl;
  } else {
    long long ans = 0;
    vector<int> b(n);
    for (int i = 0; i < m; ++i) {
      b.at(s.at(i) - 1) = c.at(i);
    }
    for (int i = 0; i < n; ++i) {
      ans += b.at(i) * pow(10, n - i - 1);
    }
    if (ans < pow(10, n - 1)) ans += pow(10, n - 1);
    if ((n == 1) && (m == 0)) ans = 0;
    cout << ans << endl;
  }
}
