#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<int, int>;
using vpi = vector<pi>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  int n, m;
  cin >> n >> m;
  vi r(n, -1);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (r[s] != -1 && r[s] != c) {
      cout << -1 << '\n';
      return 0;
    }
    r[s] = c;
  }
  if (r[0] == 0 && n != 1) {
    cout << -1 << '\n';
    return 0;
  }
  cout << (r[0] == -1 ? 1 : r[0]);
  for (int i = 0; i < (n - 1); ++i) cout << (r[i + 1] == -1 ? 0 : r[i + 1]);
  cout << '\n';
  return 0;
}
