#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int32_t N, M;
  cin >> N >> M;
  vector<int32_t> num(N, 0);
  vector<bool> visited(N, false);
  bool status = true;
  for (int q = 0; q < M; ++q) {
    int32_t s, c;
    cin >> s >> c;
    --s;
    if (visited[s]) {
      if (c != num[s]) {
        status = false;
        break;
      }
    } else {
      num[s] = c;
      visited[s] = true;
    }
  }
  if (num[0] == 0) {
    status = false;
  }
  if (status) {
    for (const auto& digit : num) {
      cout << digit;
    }
  } else {
    cout << "-1";
  }
  cout << "\n";
  return 0;
}
