#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N;
  string output = "";
  for (int i = 0; i < N; i++) {
    output += "0";
  }
  cin >> M;
  vector<vector<int>> input(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> input.at(i).at(0);
    cin >> input.at(i).at(1);
  }
  for (int i = 0; i < M; i++) {
    int si, ci;
    si = input.at(i).at(0);
    ci = input.at(i).at(1);
    if (i == 0) {
      output.at(si - 1) = ci + '0';
    } else {
      if (output.at(si - 1) - '0' == 0) {
        output.at(si - 1) = ci + '0';
      } else if (output.at(si - 1) - '0' != ci) {
        cout << "-1" << endl;
        return (0);
      }
    }
  }
  if (N == 3) {
    if (output.at(0) - '0' == 0) {
      cout << "-1" << endl;
      return (0);
    }
  } else if (N == 2) {
    if (output.at(0) - '0' == 0) {
      cout << "-1" << endl;
      return (0);
    }
  } else {
    if (output.at(0) - '0' == 0) {
      cout << "-1" << endl;
      return (0);
    }
  }
  cout << stoi(output) << endl;
  return (0);
}
