#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> data;
  int key;
  int value;
  for (int i = 0; i < m; i++) {
    cin >> key >> value;
    if (data.find(key) != data.end() && data.find(key)->second != value) {
      cout << -1 << endl;
      return 0;
    }
    data[key] = value;
  }
  if (data.find(1) != data.end() && data.find(1)->second == 0) {
    if (n == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  int ans = 0;
  for (map<int, int>::iterator i = data.begin(); i != data.end(); i++) {
    ans += i->second * pow(10, n - i->first);
  }
  if (ans < pow(10, n - 1)) {
    ans += pow(10, n - 1);
  }
  cout << ans << endl;
  return 0;
}
