#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];
  }
  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;
    cout << "-1" << endl;
    return 0;
  }
  for (int i = (0); i < (n); ++i) cout << N[i];
  return 0;
}
