#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> sc(m, vector<int>(2));
  for (size_t i = 0; i < m; i++) cin >> sc.at(i).at(0) >> sc.at(i).at(1);
  vector<int> number(n, -1);
  for (size_t i = 0; i < m; i++) {
    if (number.at(sc.at(i).at(0) - 1) == -1 ||
        number.at(sc.at(i).at(0) - 1) == sc.at(i).at(1))
      number.at(sc.at(i).at(0) - 1) = sc.at(i).at(1);
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (number.at(0) == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (number.at(0) == -1) number.at(0) = 1;
  for (size_t i = 1; i < n; i++)
    if (number.at(i) == -1) number.at(i) = 0;
  for (size_t i = 0; i < n; i++) cout << number.at(i);
  cout << endl;
}
