#include <bits/stdc++.h>
using namespace std;
void output(vector<vector<int>> number, int &N) {
  for (int i = 0; i < N; i++) {
    cout << number.at(0).at(i);
  }
}
int main() {
  int N, M, c, s;
  cin >> N >> M;
  vector<vector<int>> number(2, vector<int>(N, 0));
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (number.at(1).at(s - 1) == 0) {
      number.at(0).at(s - 1) = c;
      number.at(1).at(s - 1) += 1;
      continue;
    } else if (number.at(1).at(s - 1) > 0 && number.at(0).at(s - 1) == c) {
      continue;
    } else if (number.at(1).at(s - 1) > 0 && number.at(0).at(s - 1) != c) {
      number.at(0).at(s - 1) = 0;
    }
  }
  if (N > 1 && number.at(0).at(0) == 0) {
    cout << "-1" << endl;
  } else {
    output(number, N);
  }
}
