#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int upper = 1;
  int lower = 0;
  for (int i = 0; i < N; i++) {
    lower = upper;
    upper *= 10;
  }
  int ans = 999;
  for (int i = upper; i >= 0; i--) {
    string an = to_string(i);
    bool flag = true;
    for (int k = 0; k < M; k++) {
      string b = to_string(c[k]);
      flag = flag && an[s[k] - 1] == b[0];
    }
    if (flag) {
      ans = min(ans, i);
    }
  }
  if (ans == 999) ans = -1;
  if (ans < lower) ans = -1;
  cout << ans << endl;
  return 0;
}
