#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool hantei = false;
  bool huka = false;
  vector<bool> judge(n, false);
  vector<int> ans(n, 0);
  vector<vector<int>> data(n, vector<int>(2));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for (int i = 0; i < m; i++) {
    if (data.at(i).at(0) == 1 && data.at(i).at(1) == 0) huka = true;
    if (judge[data.at(i).at(0)] == false) {
      ans[data.at(i).at(0)] = data.at(i).at(1);
      judge[data.at(i).at(0)] = true;
    } else if (judge[data.at(i).at(0)] == true &&
               data.at(i).at(1) != ans[data.at(i).at(0)]) {
      hantei = true;
    }
  }
  if (hantei || huka)
    cout << -1 << endl;
  else {
    for (int i = 0; i < n; i++) {
      if (ans[0] == 0) ans[0] = 1;
      cout << ans[i];
    }
  }
}
