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