#include <bits/stdc++.h>
using namespace std;
const unsigned long long INF = (unsigned long long)(-1LL);
int main(void) {
  int n;
  cin >> n;
  ;
  int m;
  cin >> m;
  ;
  vector<int> ans(n, -1);
  bool error = false;
  for (unsigned long long i = (0); i < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] != -1 && ans[s] != c) error = true;
    ans[s] = c;
  }
  if (ans[0] == -1) ans[0] = 1;
  if (ans[0] == 0) error = true;
  if (error)
    cout << (-1) << endl;
  else {
    for (unsigned long long i = (0); i < (n); i++) {
      cout << (ans[i] == -1 ? 0 : ans[i]);
    }
    cout << endl;
  }
  return 0;
}
