#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;
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;
}
void END() {
  cout << 1 << endl;
  exit(0);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VI number(n, -1);
  for (int i = 0; i < (int)(m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (number[s] == -1)
      number[s] = c;
    else {
      if (number[s] != c) {
        cout << -1;
        return 0;
      }
    }
  }
  if (n == 1 && number[0] == -1) {
    cout << 0;
    return 0;
  }
  if (number[0] == 0)
    cout << -1;
  else {
    for (int i = 0; i < (int)(n); ++i) {
      if (i > 0 && number[i] == -1)
        cout << 0;
      else if (i == 0 && number[i] == -1)
        cout << 1;
      else
        cout << number[i];
    }
  }
  return 0;
}
