#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  int ans[3] = {0, 0, 0};
  bool flag = false;
  for (long long i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
    if (ans[s[i] - 1] == 0) ans[s[i] - 1] = c[i];
    if (ans[s[i] - 1] != 0 && ans[s[i] - 1] != c[i]) {
      flag = true;
    }
  }
  if (flag) {
    cout << "-1" << endl;
    return 0;
  }
  long long size = pow(10, n);
  if (m == 0) {
    if (n == 1) {
      cout << "1" << endl;
      return 0;
    }
    if (n == 2) {
      cout << "10" << endl;
      return 0;
    }
    if (n == 3) {
      cout << "100" << endl;
      return 0;
    }
  }
  if (ans[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (long long i = 0; i < (3); ++i) {
    cout << ans[i];
  }
  cout << endl;
}
