#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s.at(i) >> c.at(i);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        cout << -1 << endl;
        return 0;
      }
    }
  if (n == 1) {
    for (int i = 0; i < m; i++) {
      if ((s.at(i) == 1 || s.at(2) == 1) && c.at(i) != 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    for (int i = 0; i < m; i++) {
      if (s.at(i) == 2) {
        cout << c.at(i) << endl;
        return 0;
      }
    }
  } else if (n == 2) {
    for (int i = 0; i < m; i++) {
      if ((s.at(i) == 1) && c.at(i) != 0) {
        cout << -1 << endl;
        return 0;
      }
      if (s.at(i) == 2 && c.at(i) == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    string st = "10";
    for (int i = 0; i < m; i++) {
      if (s.at(i) == 1) {
        st.replace(0, 1, to_string(c.at(i)));
      } else if (s.at(i) == 2) {
        st.replace(1, 1, to_string(c.at(i)));
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (s.at(i) == 1 && c.at(i) == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  string st = "100";
  for (int i = 0; i < m; i++) {
    if (s.at(i) == 1) {
      st.replace(0, 1, to_string(c.at(i)));
    } else if (s.at(i) == 2) {
      st.replace(1, 1, to_string(c.at(i)));
    } else if (s.at(i) == 3)
      st.replace(2, 1, to_string(c.at(i)));
  }
  cout << st << endl;
  return 0;
}
