#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n + 1, -1);
  bool fl = true;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s] == -1)
      ans[s] = c;
    else {
      if (ans[s] == c)
        continue;
      else
        fl = false;
    }
  }
  if (n >= 2 && ans[1] == 0) fl = false;
  if (fl) {
    for (int i = 1; i <= (n); i++) {
      if (ans[i] == -1)
        cout << 0;
      else
        cout << ans[i];
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
}
