#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> data(2, vector<int>(m));
  for (int i = 0; i < m; i++) {
    cin >> data.at(i).at(0) >> data.at(i).at(1);
  }
  for (int i = 0; i < m; i++) {
    if (n = 3 && data.at(i).at(0) == 1 && data.at(i).at(0) == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (n = 2 && data.at(i).at(0) == 2 && data.at(i).at(0) == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int j = 0; j < m; j++) {
      if (data.at(i).at(0) == data.at(j).at(0) &&
          data.at(i).at(1) != data.at(j).at(1)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  int time_3 = 0;
  int time_2 = 0;
  int time_1 = 0;
  for (int i = 0; i < m; i++) {
    if (time_3 = 0 && data.at(i).at(0) == 3) {
      ans = data.at(i).at(1) * 100;
      time_3 = 1;
    }
    if (time_2 = 0 && data.at(i).at(0) == 2) {
      ans = data.at(i).at(1) * 10;
      time_2 = 1;
    }
    if (time_1 = 0 && data.at(i).at(0) == 1) {
      ans = data.at(i).at(1);
      time_1 = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
