#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> value(3, 0);
  vector<bool> change(3, false);
  value.at(N - 1) = 1;
  for (int i = 0; i < (M); ++i) {
    int s;
    int c;
    cin >> s >> c;
    if (change.at(N - s) == false) {
      value.at(N - s) = c;
      change.at(N - s) = true;
    } else if (value.at(N - s) == c) {
      value.at(N - s) = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = value.at(0) + value.at(1) * 10 + value.at(2) * 100;
  int tmp = ans;
  int digit = 0;
  if (tmp < 10) {
    digit = 1;
  } else if (tmp < 100) {
    digit = 2;
  } else {
    digit = 3;
  }
  if (digit != N)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
