#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  set<pair<int, int>> st;
  int maxs = 0;
  for (int i = 0; i < m; ++i) {
    int si, ci;
    cin >> si >> ci;
    st.insert({si, ci});
    maxs = max(maxs, si);
  }
  if (maxs != n) {
    cout << "-1";
    return 0;
  }
  for (auto& [si, ci] : st) {
    if (mp.count(si) == 0) {
      mp[si] = ci;
    } else {
      cout << "-1";
      return 0;
    }
  }
  int ret = 0;
  for (auto& [k, v] : mp) {
    ret += pow(10, n - k) * v;
  }
  if (n == 1 and ret < 10) {
    cout << ret << endl;
    return 0;
  }
  if (ret < pow(10, n - 1)) {
    ret = -1;
  }
  cout << ret << endl;
  return 0;
}
