#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
vector<int> v(5);
vector<bool> b(5);
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  for (int(i) = (0); (i) < (m); (++i)) {
    cin >> s >> c;
    s--;
    if (b[s] == true) {
      if (v[s] != c) {
        cout << (-1) << '\n';
        return (0);
      }
    }
    v[s] = c;
    b[s] = true;
  }
  if (v[0] == 0) {
    cout << (-1) << '\n';
  } else {
    for (int(i) = (0); (i) < (n); (++i)) {
      cout << (v[i]);
    }
  }
}
