#include <bits/stdc++.h>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
int power(int n, int t) {
  int s = 1;
  for (int i = 0; i < int(t); i++) {
    s *= n;
  }
  return s;
}
int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  vector<pair<int, int>> b(m);
  for (int i = 0; i < int(m); i++) {
    int s, c;
    cin >> s >> c;
    b[i] = make_pair(s, c);
  }
  for (int i = power(10, n - 1) - 1; i < int(power(10, n)); i++) {
    bool state = true;
    for (int j = 0; j < int(m); j++) {
      string num = to_string(i);
      if (num.at(b.at(j).first - 1) - '0' != b.at(j).second) {
        state = false;
        break;
      }
    }
    if (state) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
