#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    int s, c;
    int v[100];
    int w[100];
    memset(w, 0, sizeof w);
    memset(v, -1, sizeof v);
    while (m--) {
      cin >> s >> c;
      if (v[s] != c) {
        w[s]++;
      }
      v[s] = c;
    }
    bool sw = true;
    for (int i = 1; i <= n; i++) {
      if (w[i] > 1) sw = false;
      if (v[i] == -1) v[i] = 0;
    }
    if (sw) {
      if (v[1] == 0) {
        cout << "-1\n";
      } else {
        for (int i = 1; i <= n; i++) {
          cout << v[i];
        }
        cout << "\n";
      }
    } else {
      cout << "-1\n";
    }
  }
  return 0;
}
