#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> data(n, 0);
  vector<bool> flg(n, false);
  int x = 0;
  int y = 0;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (flg.at(x - 1) == false) {
      data.at(x - 1) = y;
      flg.at(x - 1) = true;
    } else {
      data.at(x - 1) = min(data.at(x - 1), y);
    }
  }
  if (n = 3) {
    if (flg.at(0) == false || flg.at(1) == false || flg.at(2) == false ||
        (flg.at(0) == true && data.at(0) == 0) ||
        (flg.at(1) == true && data.at(0) == 0)) {
      cout << -1;
      return 0;
    }
  } else if (n = 2) {
    if (flg.at(0) == false || flg.at(1) == false ||
        (flg.at(0) == true && data.at(0) == 0)) {
      cout << -1;
      return 0;
    }
  } else {
    if (flg.at(0) == false) {
      cout << -1;
      return 0;
    }
  }
  for (int j = 0; j < m; j++) {
    cout << data.at(j);
  }
}
