#include <bits/stdc++.h>
using namespace std;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vs = vector<string>;
void Main() {
  long long N, M;
  cin >> N >> M;
  vl v(N, -1);
  for (long long i = 0; i < M; i++) {
    long long in1, in2;
    cin >> in1 >> in2;
    if (v[in1 - 1] != -1 && v[in1 - 1] != in2) {
      cout << -1 << "\n";
      return;
    }
    v[in1 - 1] = in2;
  }
  string ans = "";
  if (v[0] == 0) {
    cout << -1 << "\n";
    return;
  }
  if (N == 1 && M == 0) {
    cout << 0 << "\n";
    return;
  }
  for (long long i = 0; i < N; i++) {
    if (v[i] != -1)
      ans += to_string(v[i]);
    else {
      if (i == 0)
        ans += '1';
      else
        ans += '0';
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Main();
  return 0;
}
