#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  vector<int> atai(3, 10);
  for (int i = 0; i < (int)(M); i++) {
    if (atai.at(s.at(i) - 1) == 10 || atai.at(s.at(i) - 1) == c.at(i)) {
      atai.at(s.at(i) - 1) = c.at(i);
    } else {
      ans = -1;
    }
  }
  if ((atai.at(0) == 0 && atai.at(1) > 0) ||
      (atai.at(0) == 0 && atai.at(2) > 0) ||
      (atai.at(0) == 0 && atai.at(1) == 0 && atai.at(2) > 0)) {
    ans = -1;
  }
  for (int i = 0; i < (int)(3); i++) {
    if (atai.at(i) == 10) {
      atai.at(i) = 0;
    }
  }
  if (ans != -1) {
    ans = 100 * atai.at(0) + 10 * atai.at(1) + atai.at(2);
  }
  cout << ans << endl;
  return 0;
}
