#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = ll(1e10) + 1;
void Main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n, 0);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return;
    }
    if (A[s] != 0 && A[s] != c) {
      cout << -1 << endl;
      return;
    } else
      A[s] = c;
  }
  if (A[0] == 0) A[0] = 1;
  for (int i = 0; i < (n); ++i) cout << A[i];
  cout << endl;
  return;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
