#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> used(3, -1);
  for (long long i = 0; i < (long long)m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    if (used[a] != -1 && used[a] != b) {
      cout << -1 << endl;
      return 0;
    }
    used[a] = b;
  }
  if (n == 1) {
    cout << used[0] << endl;
    return 0;
  } else if (used[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < (long long)n; i++) {
    cout << max((long long)max((long long)0, (long long)2 - i), used[i]);
  }
  cout << endl;
}
