#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> out(n, 10);
  int s, c;
  while (m--) {
    cin >> s >> c;
    if (s == 1 and c == 0 and n != 1) continue;
    out[s - 1] = min(out[s - 1], c);
  }
  if (out[0] == 10) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (out[i] == 10) {
      out[i] = 0;
    }
  }
  for (auto a : out) cout << a;
  cout << '\n';
}
