#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    vec.push_back(make_pair(s, c));
  }
  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    if (n > 1 && vec[i].first == n && vec[i].second == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 1000;
  for (int i = 999; i >= 0; i--) {
    if (i < pow(10, n - 1)) break;
    int r = i / 10;
    vector<int> seq(1, i % 10);
    while (r) {
      seq.push_back(r % 10);
      r /= 10;
    }
    reverse(seq.begin(), seq.end());
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (seq[vec[j].first - 1] != vec[j].second) ok = false;
    }
    if (ok) ans = min(ans, i);
  }
  cout << (ans == 1000 ? -1 : ans) << endl;
  return 0;
}
