#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int target[n];
  for (int i = 0; i < n; i++) {
    target[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    if (n != 1) {
      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (target[s[i]] == -1) {
      target[s[i]] = c[i];
    } else if (target[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  int answer = 0;
  for (int i = 0; i < n; i++) {
    if (target[i] == -1) {
      if (n == 1) {
        answer = 0;
      } else if (n - i == n) {
        answer += std::pow(10, n - i - 1);
      }
    } else {
      answer += target[i] * (std::pow(10, n - i - 1));
    }
  }
  cout << answer << endl;
  return 0;
}
