#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool impossible = false;
  constexpr int not_set = 1000;
  auto digits = vector<int>(n, not_set);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      impossible = true;
      break;
    }
    if (digits[n - s] != not_set && c != digits[n - s]) {
      impossible = true;
      break;
    }
    digits[n - s] = c;
  }
  if (impossible) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (digits[i] == not_set) {
      digits[i] = (i == n - 1 ? 1 : 0);
    }
  }
  int answer = 0;
  int mul = 1;
  for (int i = 0; i < n; i++, mul *= 10) {
    answer += digits[i] * mul;
  }
  cout << answer;
  return 0;
}
