#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  int ANS = -1;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < (int)(999); i++) {
    string now = to_string(999 - i);
    bool ans = true;
    for (int i = 0; i < (int)(m); i++) {
      if (now.size() >= s.at(i)) {
        if (now.at(s.at(i) - 1) != c.at(i)) ans = false;
        if (s.at(i) == 1 && c.at(i) == 0) ans = false;
      } else
        ans = false;
    }
    if (ans) ANS = stoi(now);
  }
  cout << ANS;
}
