#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = (0); i < (m); ++i) cin >> s[i] >> c[i];
  vector<int> N(n);
  for (int i = (0); i < (n); ++i) N[i] = 0;
  for (int i = (0); i < (m); ++i) {
    if (N[s[i] - 1] > c[i]) N[s[i] - 1] = c[i];
  }
  int a = 0;
  for (int i = (0); i < (n); ++i) {
    if (N[i] > 0) break;
    if (N[i] == 0) {
      a++;
      if (a == n) {
        cout << "-1" << endl;
        return 0;
      }
    }
    for (int i = (0); i < (n - a); ++i) {
      N[i] = N[i + (n - a)];
    }
  }
  for (int i = (0); i < (n); ++i) cout << N[i];
  return 0;
}
