#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> data(m);
  for (int i = 0; i < m; i++) {
    cin >> data[i].first >> data[i].second;
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    bool flag = true;
    for (int j = 0; j < m; j++) {
      int tmp = i;
      int s = data[j].first, c = data[j].second;
      s = n - s + 1;
      while (s > 1) {
        --s;
        tmp /= 10;
      }
      tmp %= 10;
      if (tmp != c) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
