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