#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vs(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (vs[s] >= 0 && vs[s] != c) {
      cout << -1 << endl;
      return 0;
    } else
      vs[s] = c;
  }
  if (n > 1 && vs[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    cout << vs[0] << endl;
    return 0;
  }
  int ret = 0;
  int keta = 1;
  for (int i = 0; i < (int)(n); i++) {
    int idx = n - i - 1;
    if (idx == 0) {
      ret += keta * max(vs[idx], 1);
    } else {
      ret += keta * max(vs[idx], 0);
    }
    keta *= 10;
  }
  cout << ret << endl;
  return 0;
}
