#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> A(5);
int main() {
  int N, M, c1, c2;
  char s[3];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> c1 >> c2;
    A[i] = make_pair(c1, c2);
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (A[i].first == A[j].first && i != j && A[i].second != A[j].second) {
        cout << -1;
        return 0;
      } else if (A[i].first == A[j].first && i != j &&
                 A[i].second == A[j].second) {
        A.erase(A.begin() + i);
      }
    }
  }
  sort(A.begin(), A.end());
  int order = 1;
  for (int i = 0; i < A.size(); i++) {
    if (A[i].first == order) {
      cout << A[i].second;
      order++;
    } else if (A[i].first > order) {
      cout << 0;
      order++;
      i--;
    }
  }
  cout << endl;
  return 0;
}
