#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  } else if (n == 2 && m == 0) {
    cout << 10 << endl;
    return 0;
  } else if (n == 3 && m == 0) {
    cout << 100 << endl;
    return 0;
  }
  bool end = false;
  if (2 <= n) {
    for (int i = 0; i < m; i++) {
      if (s[i] == 1 && c[i] == 0) end = true;
    }
  }
  if (2 <= m) {
    for (int i = 0; i < m - 1; i++) {
      for (int j = i + 1; j < m; j++) {
        if (s[i] == s[j] && c[i] != c[j]) end = true;
      }
    }
  }
  if (end) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> vec(3, 0);
  for (int i = 0; i < m; i++) {
    if (vec[s[i] - 1] < c[i]) {
      vec[s[i] - 1] = c[i];
    }
  }
  int ans;
  if (n == 1) {
    ans = vec[2];
  } else if (n == 2) {
    ans = max(1, vec[0]) * 10 + vec[1];
  } else {
    ans = max(1, vec[0]) * 100 + vec[1] * 10 + vec[2];
  }
  cout << ans << endl;
  return 0;
}
