#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, s, c;
  cin >> n >> m;
  std::deque<int> deq(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    deq[s - 1] = c;
  }
  string ho = "";
  for (int piyo = 0; piyo < n; piyo++) {
    ho += to_string(deq[piyo]);
  }
  int tmp = stoi(ho);
  string unchi = to_string(tmp);
  if (deq[0] != 0 && unchi.size() == n) {
    for (int hoge = 0; hoge < deq.size(); hoge++) {
      cout << deq[hoge];
    }
    cout << endl;
  } else if (n == 1) {
    cout << 0 << endl;
  } else {
    cout << -1 << endl;
  }
}
