#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > pairs;
  for (int i = 0; i < (m); i++) {
    int first, second;
    cin >> first >> second;
    pairs.push_back(make_pair(first, second));
  }
  sort(pairs.begin(), pairs.end());
  if (pairs[0].first != 1) {
    cout << -1 << endl;
    return 0;
  }
  pair<int, int> prev = make_pair(0, 0);
  int ans = 0;
  string sb = "";
  for (int i = 0; i < (m); i++) {
    pair<int, int> curr = pairs[i];
    if (curr.first == prev.first && curr.second != prev.second) {
      ans = -1;
      break;
    }
    if (curr.first == prev.first) continue;
    if (curr.first > prev.first + 1) {
      int ct = curr.first - prev.first - 1;
      for (int j = 0; j < (ct); j++) sb.push_back('0');
    }
    sb += to_string(curr.second);
    prev = curr;
  }
  if (ans == -1) {
    cout << ans << endl;
  } else
    cout << stoi(sb) << endl;
  return 0;
}
