#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> digits(n, -1);
  bool exists = true;
  int s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    int idx = n - s;
    if ((n > 1 && s == 1 && c == 0) ||
        (digits[idx] != -1 && digits[idx] != c)) {
      exists = false;
      break;
    }
    digits[idx] = c;
  }
  if (!exists) {
    cout << -1 << "\n";
    return 0;
  }
  if (digits[n - 1] == -1) {
    digits[n - 1] = 1;
  }
  int result = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (digits[i] != -1) {
      result += pow(10, i) * digits[i];
    }
  }
  cout << result << "\n";
  return 0;
}
