#include <bits/stdc++.h>
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> vec;
  for (int i = 0; i < n; i++) {
    vec.push_back(-1);
  }
  std::map<int, int> mp;
  int inp;
  int inp_;
  for (int i = 0; i < m; i++) {
    cin >> inp;
    cin >> inp_;
    auto itr = mp.find(inp);
    if (itr != mp.end()) {
      if (mp[inp] != inp_) {
        cout << "-1";
        return 0;
      }
    } else {
      mp[inp] = inp_;
      vec[inp - 1] = inp_;
    }
  }
  if (n == 1) {
    if (vec[0] == -1) vec[0] = 0;
  } else {
    if (vec[0] == -1) vec[0] = 1;
  }
  if (n > 1) {
    for (int i = 1; i < n; i++) {
      if (vec[i] == -1) vec[i] = 0;
    }
  }
  for (int i : vec) {
    cout << i;
  }
  return 0;
}
