#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end());
  bool f = true;
  for (int i = 0; i < m; i++) {
    if (v[i].first == 1 && v[i].second == 0) {
      f = false;
      break;
    }
    if (i != m - 1 && m > 1) {
      if (v[i].first == v[i + 1].first && v[i].second != v[i + 1].second) {
        f = false;
        break;
      }
    }
  }
  if (f) {
    int a, b, c = 0;
    for (int i = 0; i < m; i++) {
      if (v[i].first == 1) {
        a = v[i].second * 100;
      } else if (v[i].first == 2) {
        b = v[i].second * 10;
      } else {
        c = v[i].second;
      }
    }
    if (a == -1) {
      a = 100;
    }
    cout << a + b + c << endl;
  } else {
    cout << -1 << endl;
  }
}
