#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;
int f(int n) {
  int ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= 10;
  }
  return ans;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vi> data(M, vi(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j);
    }
  }
  int ans = f(N - 1);
  while (ans < f(N)) {
    bool check = false;
    for (int i = 0; i < M; i++) {
      int a = ans / f(N - data.at(i).at(0));
      if (a % 10 != data.at(i).at(1)) {
        check = true;
        break;
      }
    }
    if (!check) {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
  cout << -1 << endl;
}
