#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.at(i) >> c.at(i);
  }
  int start;
  if (n == 0)
    start = 0;
  else
    start = pow(10, n - 1);
  for (int i = start; i < pow(10, n); i++) {
    bool flag = true;
    string t = to_string(i);
    for (int i = 0; i < m; i++) {
      int digit = s.at(i) - 1;
      int num = c.at(i);
      if (t.at(digit) != (char)(num + '0')) flag = false;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
