#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  string number = "";
  for (int i = 0; i < (int)(N); i++) {
    number.push_back('1');
  }
  vector<bool> judge(N, true);
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    if (judge.at(s - 1) == false) {
      if (number.at(s - 1) != c + 48) {
        puts("-1");
      }
    } else {
      judge.at(s - 1) = false;
      number.at(s - 1) = c + 48;
    }
  }
  cout << (to_string(stoi(number)).size() == N ? stoi(number) : -1) << endl;
  return 0;
}
