#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a;
  cin >> n >> m;
  int p[3] = {11, 11, 11};
  int s[m];
  int c[m];
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    if (n == 2) {
      cout << 10 << endl;
      return 0;
    }
    if (n == 3) {
      cout << 100 << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    if (s[i] > n) {
      cout << -1 << endl;
      return 0;
    }
    if (p[s[i] - 1] == 11) {
      p[s[i] - 1] = c[i];
    } else if (p[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (p[0] == 11) p[0] == 1;
  if (n != 0 && p[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (p[i] == 11) {
      p[i] = 0;
    }
    cout << p[i];
  }
  cout << endl;
  return 0;
}
