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