#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N;
  vector<int> S(N, -1);
  cin >> M;
  for (int i = 0; i < (int)(M); ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (S[s] != -1 && S[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    S[s] = c;
  }
  bool ok = false;
  for (int i = 0; i < (int)(N); ++i) {
    if (!ok && S[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (S[i] == -1) {
      cout << (ok ? 0 : 1);
    } else {
      cout << S[i];
    }
    ok = true;
  }
  cout << endl;
  return 0;
}
