#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> dig(N, 10);
  bool judge = 1;
  for (int i = 0; i < M; i++) {
    cin >> s.at(i);
    cin >> c.at(i);
    for (int j = 0; j < N; j++) {
      if ((j == (s.at(i) - 1)) && (dig.at(j) != c.at(i)) && (dig.at(j) != 10))
        judge = 0;
      else if (j == (s.at(i) - 1))
        dig.at(j) = c.at(i);
    }
  }
  for (int i = 0; i < N; i++) {
    if (dig.at(i) == 10) dig.at(i) = 0;
  }
  if ((dig.at(0) == 0) || (judge == 0))
    cout << "-1" << endl;
  else
    cout << to_string(dig.at(0)) + to_string(dig.at(1)) + to_string(dig.at(2))
         << endl;
}
