#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.at(i) >> C.at(i);
  for (int i = 0; i < 1000; i++) {
    string s = to_string(i);
    if (s.size() != N) continue;
    if (s.size() == 1)
      s = "00" + s;
    else if (s.size() == 2)
      s = "0" + s;
    bool isMatch = true;
    for (int j = 0; j < M; j++) {
      if (s.at(S.at(j) - 1) != C.at(j)) isMatch = false;
    }
    if (isMatch) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
