#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    bool ch = true;
    string st = to_string(i);
    for (int j = 0; j < m; j++) {
      char di = '0' + c[j];
      if (st.at(s[j] - 1) != di) {
        ch = false;
      }
    }
    if (ch) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
