#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  int temp_s, temp_c;
  for (int i = 0; i < m; ++i) {
    cin >> temp_s;
    cin >> temp_c;
    sc[i] = make_pair(temp_s, temp_c);
  }
  unordered_map<int, int> um;
  for (auto t : sc) {
    if (um.find(t.first) != um.end()) {
      if (um.at(t.first) != t.second) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      um.emplace(t.first, t.second);
    }
  }
  if (n > 1) {
    if (um.find(1) != um.end()) {
      if (um.at(1) == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  string result = "";
  for (int i = 1; i <= n; ++i) {
    if (um.find(i) != um.end()) {
      result += to_string(um.at(i));
    } else {
      if (i == 1) {
        result += "1";
      } else {
        result += "0";
      }
    }
  }
  cout << result << endl;
  return 0;
}
