#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;
    out[s - 1] = min(out[s - 1], c);
  }
  if (out[0] == 10) {
    cout << "-1\n";
    return 0;
  }
  bool check = true;
  if (out[0] == 0) {
    check = false;
  }
  for (int i = 0; i < n; i++) {
    if (out[i] == 10) {
      out[i] = 0;
      if (!check) {
        cout << "-1\n";
        return 0;
      }
    } else if (out[i] != 0) {
      check = true;
    }
  }
  bool valid = false;
  for (auto a : out) {
    if (a == 0 and !valid) continue;
    cout << a;
    valid = true;
  }
  if (check == false) cout << "0";
  cout << '\n';
}
