#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c, x = 10, y = 10, z = 10, sum = 0;
  cin >> n >> m;
  for (int i; i < m; i++) {
    cin >> s >> c;
    if ((s == 1 && c == 0) && n != 1) {
      sum = 1;
      break;
    } else if (n - s == 0 && (z == 10 || z == c))
      z = c;
    else if (n - s == 1 && (y == 10 || y == c))
      y = c;
    else if (n - s == 2 && (x == 10 || x == c))
      x = c;
    else
      sum = 1;
  }
  if (x == 10) x = 0;
  if (y == 10) y = 0;
  if (z == 10) z = 0;
  if (sum == 1)
    cout << -1 << endl;
  else if (n == 1)
    cout << z << endl;
  else if (n == 2)
    cout << 10 * y + z << endl;
  else if (n == 3)
    cout << 100 * x + 10 * y + z << endl;
}
