#include <bits/stdc++.h>
using namespace std;
using VP = vector<pair<long long, long long> >;
using VVP = vector<VP>;
using VI = vector<long long>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const long long INF = 1LL << 61;
const long long mod = 1e9 + 7;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int i, j;
  int n, m;
  cin >> n >> m;
  VI v(n + 1, -1);
  for (i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (v[s] >= 0 && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  if (v[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (i = 1; i <= n; i++) {
    if (i == 1)
      cout << max(1ll, v[i]);
    else
      cout << max(0ll, v[i]);
  }
  cout << endl;
}
