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