#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, M;
vector<int> vec_s;
vector<char> vec_c;
bool check(string ans) {
  bool isOK = true;
  for (int i = 0; i < M; i++) {
    int idx = vec_s[i] - 1;
    char c = vec_c[i];
    if (ans[idx] != c) {
      isOK = false;
      break;
    }
  }
  return isOK;
}
int resolve() {
  for (int i = 0; i < 999; i++) {
    string str_ans = to_string(i);
    if (check(str_ans)) return i;
  }
  return -1;
}
bool check_digit() {
  if (N == 1) return true;
  for (int i = 0; i < M; i++) {
    int head = vec_s[i];
    char c = vec_c[i];
    if (head == 1 && c == '0') return false;
  }
  return true;
}
int main() {
  cin >> N >> M;
  int ans = -1;
  for (int i = 0; i < M; i++) {
    int tmp_s;
    char tmp_c;
    cin >> tmp_s >> tmp_c;
    vec_s.push_back(tmp_s);
    vec_c.push_back(tmp_c);
  }
  if (check_digit()) ans = resolve();
  cout << ans << endl;
  return 0;
}
