#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;
long long pow(int x, int y) {
  long long ans = 1;
  for (int i = 0; i < y; i++) {
    ans *= x;
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  map<int, int> map;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    auto iterator = map.find(s);
    if (iterator != map.end() && iterator->second != c) {
      cout << -1 << endl;
      return 0;
    }
    if (s == 1 && c == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    if (s > n) {
      cout << -1 << endl;
      return 0;
    }
    map.insert(make_pair(s, c));
  }
  long long ans = 0;
  auto ite0 = map.find(0);
  if (ite0 == map.end()) ans += pow(10, (n - 1));
  for (auto it = map.begin(); it != map.end(); it++) {
    ans += pow(10, (n - it->first)) * it->second;
  }
  cout << ans << endl;
  return 0;
}
