#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i);
    cin >> c.at(i);
  }
  for (int x = pow(10, n - 1); x < pow(10, n); x++) {
    bool can = true;
    string num_s = to_string(x);
    if (m == 0) {
      if (n == 1) cout << 0 << endl;
      cout << x << endl;
      return 0;
    }
    for (int i = 0; i < m; i++) {
      int num = s.at(i) - 1;
      if (!(num_s.at(num) == c.at(i))) {
        can = false;
        break;
      }
    }
    if (can == true) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
