#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n, m;
  cin >> n >> m;
  vi s(m);
  vector<char> c(m);
  bool flag = false;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int a = 1;
  for (int i = 0; i < (int)(n - 1); i++) {
    a *= 10;
  }
  for (int i = a; i < (a * 10); i++) {
    string S = to_string(i);
    int j = 0;
    while (true) {
      if (S.at(s.at(j) - 1) != c.at(j)) {
        break;
      } else if (j == m - 1) {
        cout << S << endl;
        return 0;
      }
      j++;
    }
  }
  cout << -1 << endl;
}
