#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> sc(M);
  for (int i = 0; i < M; i++) cin >> sc[i].first >> sc[i].second;
  bool can = false;
  int res = -1;
  for (int i = 0; i < pow(10, N); i++) {
    string tmp = to_string(i);
    if (tmp.size() == N) {
      for (int j = 0; j < M; j++) {
        if (tmp[sc[j].first - 1] != sc[j].second) {
          can = false;
          break;
        }
        can = true;
      }
    }
    if (can) {
      res = i;
      break;
    }
  }
  cout << res << endl;
}
