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