#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> e;
  if (m == 0) {
    if (n == 1) cout << 1 << endl;
    if (n == 2) cout << 10 << endl;
    if (n == 3) cout << 100 << endl;
    return 0;
  }
  vector<vector<int>> s(m, vector<int>(2));
  for (auto &p : s) {
    for (auto &t : p) {
      cin >> t;
    }
  }
  for (auto &p : s) {
    if (!e.count(p.at(0))) {
      e[p.at(0)] = p.at(1);
    } else if (p.at(1) != e.at(p.at(0))) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (e.count(1)) {
    if (e.at(1) == 0) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 1; i < n + 1; i++) {
    if (e.count(i)) {
      cout << e.at(i);
    } else if (i == 1) {
      cout << 1;
    } else
      cout << 0;
  }
}
