#include <bits/stdc++.h>
using namespace std;
class CGuessTheNumber {
 public:
  void solve(std::istream& cin, std::ostream& cout) {
    long long N, M;
    cin >> N >> M;
    char* n = new char[N];
    for (int i = 0; i < N; ++i) {
      n[i] = 0;
    }
    for (int i = 0; i < M; ++i) {
      long long s, c;
      cin >> s >> c;
      if (n[s - 1] != 0 && n[s - 1] != c + '0') {
        cout << -1;
        return;
      }
      n[s - 1] = c + '0';
    }
    if (N != 1 && n[0] == '0') {
      cout << -1;
      return;
    }
    for (int i = 0; i < N; ++i) {
      cout << (n[i] == 0 ? '0' : n[i]);
    }
  }
};
int main() {
  CGuessTheNumber solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
