#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  int s[100100];
  int c[100100];
  int nn[4];
  int nf[4];
  int tr = 1;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    nn[i] = 0;
    nf[i] = 0;
  }
  for (int i = 1; i <= m; ++i) {
    cin >> s[i] >> c[i];
    if (nf[s[i]] == 0) {
      nf[s[i]] = 1;
      nn[s[i]] = c[i];
    }
    if (nn[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (tr == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= n; ++i) {
      if ((i == 1) && (n >= 1) && (nn[i] == 0)) {
        cout << -1;
        break;
      }
      cout << nn[i];
    }
    cout << endl;
  }
}
