#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int lim = 1;
  for (int i = 0; i < n; i++) {
    lim *= 10;
  }
  string num_str;
  int ans = -1;
  bool ans_flag;
  for (int i = 1; i < lim; i++) {
    ans_flag = true;
    num_str = to_string(i);
    for (int j = 0; j < m; j++) {
      if (s[j] > num_str.size()) {
        ans_flag = false;
        break;
      }
      if (num_str[s[j] - 1] - '0' != c[j]) {
        ans_flag = false;
        break;
      }
    }
    if (ans_flag) {
      ans = i;
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
