#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  bool is_satisfied = true;
  vector<char> guess(N, 'X');
  for (int i = 0; i < M; i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (N > 1 && s == 0 && c == '0') {
      is_satisfied = false;
      break;
    } else if (guess.at(s) == 'X') {
      guess.at(s) = c;
    } else if (guess.at(s) != c) {
      is_satisfied = false;
      break;
    }
  }
  if (is_satisfied) {
    if (guess.at(0) == 'X') {
      cout << '1';
    } else {
      cout << guess.at(0);
    }
    for (int i = 1; i < N; i++) {
      if (guess.at(i) == 'X') {
        cout << '0';
      } else {
        cout << guess.at(i);
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
