#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[4] = {-1, -1, -1, -1}, n, m, sum = 0, b, c;
  cin >> n >> m;
  while (m--) {
    cin >> b >> c;
    if (a[b] != -1) {
      if (a[b] != c) {
        cout << -1 << endl;
        return 0;
      } else {
        continue;
      }
    }
    a[b] = c;
    sum += c * (int)(pow(10, n - b) + 0.5);
  }
  if (n > 0 && a[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (n > 1 && a[i] == 0) {
      sum += 1 * (int)(pow(10, n - b) + 0.5);
    }
  }
  cout << sum << endl;
  return 0;
}
