#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> tmp_value(n, 0);
  bool duplicate_flag = false;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (0 == tmp_value[s - 1] || c == tmp_value[s - 1]) {
      tmp_value[s - 1] = c;
    } else {
      duplicate_flag = true;
    }
  }
  int value = 0;
  for (int i = 0; i < n; i++) {
    value += tmp_value[n - i - 1] * pow(10, i);
  }
  int num_digits = to_string(value).length();
  if (n != num_digits) {
    duplicate_flag = true;
  }
  if (duplicate_flag) {
    cout << -1 << endl;
  } else {
    cout << value << endl;
  }
  return 0;
}
