#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, d[5];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (a > n || (d[i] != 0 && b != d[a]) || (a == 1 && b == 0 && n != 1)) {
      cout << -1 << endl;
      return 0;
    } else
      d[a] = b;
  }
  for (int i = 1; i <= n; i++) cout << d[i];
  cout << endl;
}
