#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int ans = -1;
  int n, m;
  cin >> n >> m;
  if (!m) {
    cout << 0 << '\n';
    return 0;
  }
  map<int, int> S;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (S[a] && S[a] != b) {
      cout << ans << '\n';
      return 0;
    }
    S[a] = b;
  }
  int cc = 0;
  for (auto x : S) {
    if (x.second) {
      ++cc;
    }
  }
  if (!cc) {
    cout << -1 << '\n';
    return 0;
  }
  int c = 0;
  for (int i = 0; i < n; ++i) {
    if (!S[i + 1] && !c) {
      continue;
    }
    cout << S[i + 1];
    ++c;
  }
  cout << '\n';
}
