#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  Vi s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  Vi vec(N, -1);
  bool is_zero = false;
  bool dame = false;
  for (int i = 0; i < M; i++) {
    if (s[i] - 1 == 0 && c[i] == 0) {
      if (N > 1) {
        dame = true;
        break;
      } else {
        is_zero = true;
      }
    }
    if (vec[s[i] - 1] == -1) {
      vec[s[i] - 1] = c[i];
    } else {
      if (vec[s[i] - 1] != c[i]) {
        dame = true;
        break;
      }
    }
  }
  if (dame) {
    cout << -1 << endl;
    return 0;
  }
  if (is_zero) {
    cout << 0 << endl;
    return 0;
  }
  string ans;
  for (int i = 0; i < N; i++) {
    if (vec[i] == -1 && i == 0) {
      ans += '1';
    } else {
      if (vec[i] == -1) {
        ans += '0';
      } else {
        ans += vec[i] + '0';
      }
    }
  }
  cout << ans << endl;
  return 0;
}
