#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[5] = {0}, n, m, i, x, y, j, f = 0;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> x >> y;
    if (a[x] == 0) {
      a[x] = y;
    } else {
      f++;
    }
  }
  if (f > 0) {
    cout << -1 << endl;
  } else if (n == 1) {
    cout << a[1] << endl;
  } else if (n > 1) {
    for (j = 1; j <= n; j++) {
      if (a[1] == 0) {
        cout << -1;
        break;
      }
      cout << a[j];
    }
    cout << endl;
  }
  return 0;
}
