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