#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main() {
  int n, m;
  cin >> n >> m;
  int s;
  int c[n];
  for (int i = 0; i < n; ++i) c[i] = INF;
  int tmp;
  for (int i = 0; i < m; ++i) {
    cin >> s;
    cin >> tmp;
    c[s - 1] = min(c[s - 1], tmp);
  }
  for (int i = 0; i < n; ++i) {
    if (c[i - 1] == INF) {
      c[i - 1] = 0;
    }
  }
  if (c[0] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; ++i) cout << c[i];
    cout << endl;
  }
  return 0;
}
