#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;
const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;
template <class T, class S>
bool chmax(T &a, const S &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class S>
bool chmin(T &a, const S &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int N, M;
  cin >> N >> M;
  VI a(N, 0);
  VB b(N, false);
  for (int i = (0), i_len = (M); i < i_len; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (b[s] && a[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s] = c;
  }
  if (N != 1 && a[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = (0), i_len = (N); i < i_len; ++i) cout << a[i];
  cout << endl;
  return 0;
}
