#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 1; i < m; i++) {
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (n >= 2 && s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 1) {
    cout << c[0] << endl;
  }
  if (n == 2) {
    int a = 1;
    int b = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1) a = c[i];
      if (s[i] == 2) b = c[i];
    }
    cout << 10 * a + b << endl;
  }
  if (n == 3) {
    int p = 1;
    int q = 0;
    int r = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1) p = c[i];
      if (s[i] == 2) q = c[i];
      if (s[i] == 3) r = c[i];
    }
    cout << 100 * p + 10 * q + r << endl;
  }
}
