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