#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<set<int>> vec(10);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    vec[a].insert(b);
  }
  for (int i = 1; i <= M; ++i) {
    if (vec[i].size() > 1) {
      cout << "-1\n";
      return 0;
    }
  }
  for (int i = 0; i < pow(10, N); ++i) {
    string tmp = to_string(i);
    long long keta = tmp.size();
    if (keta == N) {
      int counta = 0;
      for (int j = 1; j < keta + 1; ++j) {
        if (*vec[j].begin() == tmp[j - 1] - '0') counta++;
      }
      if (counta == keta) {
        cout << tmp << endl;
        return 0;
      }
    }
  }
  cout << "-1" << endl;
}
