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