#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N, -1);
  for (int i = 0; i < M; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    if ((a[x] != -1 and a[x] != y) or (x == 0 and y == 0)) {
      cout << -1 << '\n';
      return 0;
    } else {
      a[x] = y;
    }
  }
  vector<int> b(N, 0);
  b[0] = max(a[0], 1);
  for (int i = 1; i < N; ++i) {
    if (a[i] != -1) b[i] = a[i];
  }
  for (auto x : b) cout << x;
  cout << '\n';
  return 0;
}
