#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 < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(), p.end());
  if (!m) {
    if (n == 1) {
      cout << 0 << endl;
    } else {
      cout << pow(10, n - 1) << endl;
    }
    return 0;
  }
  vector<int> v(n + 1);
  for (int i = 0; i < n; i++) v[i] = 0;
  for (int i = 0; i < m; i++) {
    int s = p[i].first, c = p[i].second;
    if ((s == 1 && c == 0) || (v[s] && v[s] != c) || s > n) {
      cout << "-1" << endl;
      return 0;
    }
    v[s] = c;
  }
  if (!v[1]) v[1] = 1;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = ans + v[i] * (pow(10, (n - i)));
  }
  cout << ans << endl;
  return 0;
}
