#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[100], c[100];
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  vector<int> v;
  for (int i = 0; i < 3; i++) {
    v.push_back(10);
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1) {
      if (c[i] < v[0] and c[i] != 0) v[0] = c[i];
    }
    if (s[i] == 2) {
      if (c[i] < v[1]) v[1] = c[i];
    }
    if (s[i] == 3) {
      if (c[i] < v[2]) v[2] = c[i];
    }
  }
  if (v[1] == 10) v[1] = 0;
  if (v[2] == 10) v[2] = 0;
  if (n == 1) {
    if (v[0] == 10)
      cout << 0 << endl;
    else
      cout << v[0] << endl;
  } else {
    if (v[0] == 10)
      cout << -1 << endl;
    else {
      for (int i = 0; i < n; i++) {
        cout << v[i];
      }
      cout << endl;
    }
  }
  return 0;
}
