#include <bits/stdc++.h>
using namespace std;
int iy[] = {0, 0, 1, -1};
int ix[] = {1, -1, 0, 0};
int n, m, s[7], c[7], sum, f;
bool a[4][10], ans, fl;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    a[n + 1 - s[i]][c[i]] = true;
  }
  if (a[n][0] && n != 1) ans = true;
  for (int i = n; i >= 1; i--) {
    fl = false;
    f = 0;
    for (int j = 9; j >= 0; j--) {
      if (a[i][j]) {
        if (fl) ans = true;
        fl = true;
        f = j;
      }
    }
    if (fl) sum += f * pow(10, i - 1);
    if (!fl && i == n) sum += pow(10, i - 1);
  }
  if (ans) {
    cout << "-1" << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}
