#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ds(N, -1);
  bool failure = false;
  int s, c;
  for (int i = 0; i < M; ++i) {
    cin >> s >> c;
    auto idx = s - 1;
    if (ds[idx] != -1) {
      failure = ds[idx] != c;
    } else {
      ds[idx] = c;
    }
  }
  if (failure) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < ds.size(); ++i) {
    if (i == 0 && ds[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ds[i] == -1) {
      cout << (i == 0 ? 1 : 0);
    } else {
      cout << ds[i];
    }
  }
  cout << endl;
  return 0;
}
