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