#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI = 2147483647;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline T powerM(T a, T b) {
  if (b == 0) return 1;
  T tmp = powerM(a, b / 2);
  if (b % 2 == 0)
    return tmp * tmp % MOD;
  else
    return tmp * tmp % MOD * a % MOD;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) cin >> s.at(i) >> c.at(i);
  bool zero = false;
  for (int i = 0; i < (int)(m); i++)
    if (s.at(i) == 1 && c.at(i) == 0) zero = true;
  vector<int> num(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    if (num.at(s.at(i) - 1) != -1 && num.at(s.at(i) - 1) != c.at(i)) {
      cout << -1 << endl;
      return;
    }
    num.at(s.at(i) - 1) = c.at(i);
  }
  if (zero && n == 1) {
    cout << 0 << endl;
    return;
  }
  if (zero) {
    cout << -1 << endl;
    return;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (i == 0) {
      cout << (num.at(i) == -1 ? 1 : num.at(i));
    } else {
      cout << (num.at(i) == -1 ? 0 : num.at(i));
    }
  }
  cout << endl;
}
int main() { solve(); }
