#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vector<T>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vec<int> ns(N, -1);
  for (ll i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (ns[s] != -1 && ns[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    ns[s] = c;
  }
  bool topFilled = false;
  for (ll i = 0; i < N; ++i) {
    if (!topFilled && ns[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << (ns[i] == -1 ? 0 : ns[i]);
    topFilled = true;
  }
  return 0;
}
