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