#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int min = 1;
  for (int i = 0; i < n - 1; i++) min *= 10;
  int s, c;
  vector<int> digits = {-1, -1, -1};
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (n != 1 && s == 1 && c == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if ((digits.at(s - 1) != -1) && (digits.at(s - 1) != c)) {
      cout << "-1" << endl;
      return 0;
    }
    digits.at(s - 1) = c;
  }
  for (int i = 0; i < n; i++) {
    if (digits.at(i) == -1)
      cout << 0;
    else
      cout << digits.at(i);
  }
  cout << endl;
  return 0;
}
