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