#include <bits/stdc++.h>
using namespace std;
bool s[4][10];
int main() {
  int n, m, a, b;
  cin >> n >> m;
  int num = 0, w = 0, r = 0, t = 0;
  while (m--) {
    cin >> a >> b;
    s[a][b] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 9; j++) {
      if (s[i][j] == 1) {
        if (i == 1 && j == 0) {
          cout << "-1" << endl;
          break;
        } else {
          int p = pow(10.0, n - i);
          num += j * p;
          if (i == 1) w++;
          if (i == 2) r++;
          if (i == 3) t++;
        }
      }
    }
  }
  if (w > 1 || r > 1 || t > 1)
    cout << "-1" << endl;
  else if (s[1][0] != 1)
    cout << num << endl;
}
