#include <bits/stdc++.h>
using namespace std;
long long pow(long long a, int n) {
  long long tmp = 1;
  while (n) {
    tmp *= a;
    n--;
  }
  return tmp;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> first(n, true);
  vector<int> keta(n, 0);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    s--;
    if (!first.at(s)) {
      if (c != keta.at(s)) {
        cout << -1 << endl;
        return 0;
      }
    } else if (first.at(s)) {
      keta.at(s) = c;
      first.at(s) = false;
    }
  }
  int ans = 0;
  if (first.at(0)) {
    ans += pow(10, n - 1);
    if (n == 1) {
      ans = 0;
    }
  }
  for (int i = 1; i < n; i++) {
    if (!first.at(i)) {
      ans += keta.at(i) * pow(10, n - i - 1);
    }
  }
  cout << ans << endl;
}
