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