#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> save(N + 1, -1);
  for (long long i = 0; i < M; i++) {
    long long a, b;
    cin >> a >> b;
    if (save[a] == -1) {
      save[a] = b;
    } else if (save[a] == b) {
      save[a] = b;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (save[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (long long i = 1; i <= N; i++) {
    if (save[i] != -1) {
      cout << save[i];
    } else {
      if (i == 1)
        cout << 1;
      else
        cout << 0;
    }
  }
  cout << endl;
  return 0;
}
