#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve_1() {
  int N, M;
  cin >> N >> M;
  map<int, char> digitMap;
  bool isNoAnswer = false;
  for (int i = 0; i < M; i++) {
    int s;
    char c;
    cin >> s >> c;
    if (N != 1 && s == 1 && c == '0') {
      isNoAnswer = true;
      break;
    }
    if (digitMap.count(s) == 0) {
      digitMap[s] = c;
    } else if (digitMap[s] != c) {
      isNoAnswer = true;
      break;
    } else {
    }
  }
  if (isNoAnswer) {
    cout << -1 << endl;
  } else {
    char ans[4];
    if (N == 1) {
      ans[0] = digitMap.count(1) ? digitMap[1] : '0';
    } else {
      for (int i = 0; i < N; i++) {
        if (digitMap.count(i + 1)) {
          ans[i] = digitMap[i + 1];
        } else {
          ans[i] = i == 0 ? '1' : '0';
        }
      }
    }
    cout << ans << endl;
  }
}
void solve_2() {
  int ans = -1;
  int N, M;
  cin >> N >> M;
  map<int, char> numMap;
  for (int i = 0; i < N; i++) {
    int s;
    char c;
    cin >> s >> c;
    if (numMap.count(s) != 0 && numMap[s] != c) {
      cout << -1 << endl;
      return;
    }
    if (N != 1 && s == 1 && c == '0') {
      cout << -1 << endl;
      return;
    }
    numMap[s] = c;
  }
  int max = int(pow(10, N));
  for (int i = 0; i < max; i++) {
    string ans_s = to_string(i);
    string i_s = to_string(i);
    if (i_s.size() != N) continue;
    bool foundAns = true;
    for (int j = 0; j < M; j++) {
      if (numMap.count(j + 1) != 0) {
        if (i_s[j] != numMap[j + 1]) {
          foundAns = false;
          break;
        }
      }
    }
    if (foundAns) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
int main() {
  solve_2();
  return 0;
}
