#include <bits/stdc++.h>
using namespace std;
int N, M;
bool ok = true;
int main() {
  cin >> N >> M;
  vector<int> sc(N + 5, -1);
  int s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (s == 1 && c == 0 && N > 1) ok = false;
    if (sc[s] != -1 && sc[s] != c) ok = false;
    sc[s] = c;
  }
  if (ok) {
    for (int i = 1; i <= N; i++) {
      if (sc[i] < 0)
        cout << 0;
      else
        cout << sc[i];
    }
  } else
    cout << -1;
  cout << endl;
}
