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