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