#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> p;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (!p.count(s))
      p[s] = c;
    else if (p[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int ans = 0;
  for (auto q : p) {
    auto s = q.first;
    auto c = q.second;
    if (n > 1 && s == 1 && c == 0) {
      cout << "0" << endl;
      return 0;
    }
    if (s == 1 && c == 0) {
      cout << "-1" << endl;
      return 0;
    }
    ans += (int)pow(10, n - s) * c;
  }
  if (n > 1 && !p.count(1)) ans += (int)pow(10, n - 1);
  cout << ans << endl;
}
