#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> checked(n, true);
  int ans = 0;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (n > 1 && s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    int po = ans;
    if (n == 3) {
      if (s == 1) {
        for (int j = 0; j < (2); ++j) po /= 10;
      }
      if (s == 2) {
        int poo = ans / 100;
        po /= 10;
        po -= poo * 10;
      }
      if (s == 3) {
        po %= 10;
      }
    }
    if (n == 2) {
      if (s == 1) {
        po /= 10;
      }
      if (s == 3) {
        po %= 10;
      }
    }
    if (checked[(n - s)]) {
      ans += c * pow(10, (n - s));
      checked[(n - s)] = false;
    } else if (c == po) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int po = 1;
  for (int i = 0; i < (n - 1); ++i) po *= 10;
  if (po > ans) ans += po;
  cout << ans << endl;
}
