#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c, q, w = 0;
  string ans = "0";
  cin >> n >> m;
  cin >> s >> c;
  int p = c;
  for (int r = 1; r <= m; p++) {
    cin >> s >> c;
    if (ans[s - 1] == p) {
      p = ans[s - 1];
      if (w == m) {
        cout << ans;
        return 0;
      }
    } else {
      cout << "-1";
      return 0;
    }
  }
  return 0;
}
