#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > as(m);
  for (int i = 0; i < (int)(m); i++) cin >> as.at(i).first >> as.at(i).second;
  for (auto x : as) {
    for (auto y : as) {
      if (x == y)
        break;
      else if (x.first == y.first && x.second != y.second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  bool judge;
  for (int i = 0; i < (int)(1000); i++) {
    judge = true;
    string s = to_string(i);
    if (s.size() != n) continue;
    for (auto x : as) {
      string second = to_string(x.second);
      if (s.at(x.first - 1) != second.at(0)) {
        judge = false;
        break;
      }
    }
    if (judge) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
