#include <bits/stdc++.h>
using namespace std;
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[i] >> C[i];
  }
  for (int i = 0; i < pow(10, n); i++) {
    int flag = 1;
    string s = to_string(i);
    for (int j = 0; j < m; j++) {
      if (s[S[j] - 1] != C[j]) flag = 0;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
