#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> sc(M);
  for (int(i) = 0; (i) < (M); (i)++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    sc[i] = {s, c};
  }
  int ans = 100000;
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    string t = to_string(i);
    bool ac = true;
    for (int m = 0; m < M; m++) {
      int s, c;
      tie(s, c) = sc[m];
      ac &= (t[s] == c);
    }
    if (ac) ans = min(ans, i);
  }
  if (ans == 100000)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
