#include <bits/stdc++.h>
using namespace std;
int main() {
  struct SC {
    int s;
    int c;
  };
  int n, m;
  cin >> n >> m;
  vector<SC> scs(m);
  for (int i = 0; i < m; i++) {
    cin >> scs[i].s >> scs[i].c;
  }
  sort(scs.begin(), scs.end(),
       [](const SC& x, const SC& y) { return x.s > x.c; });
  for (int i = 0; i < scs.size(); i++) {
    cout << scs[i].s << scs[i].c << endl;
  }
  int ans = 0;
  int num = 0;
  for (int i = 1; i < n + 1; i++) {
    num = -1;
    while (!scs.empty() && scs.back().s == i) {
      if (num == -1) {
        num = scs.back().c;
      } else if (scs.back().c != num) {
        cout << -1 << endl;
        return 0;
      }
      scs.pop_back();
    }
    if (n == 1 && (num == -1 || num == 0)) {
      cout << 0 << endl;
      return 0;
    }
    if (num == 0 && i == 1) {
      cout << -1 << endl;
      return 0;
    } else if (num == -1 && i == 1) {
      num = 1;
    } else if (num == -1) {
      num = 0;
    }
    ans += num * pow(10, (n + 1 - i)) / 10;
  }
  cout << ans << endl;
  return 0;
}
