#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), c(m), ans(n, -1);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  if (n > m) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (ans[s[i] - 1] == -1)
      ans[s[i] - 1] = c[i];
    else if (ans[s[i] - 1] == c[i])
      continue;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  string x;
  for (int i = 0; i < n; i++) {
    if (ans[i] == -1) {
      if (i == n - 1)
        ans[i] = 1;
      else
        ans[i] = 0;
    }
    x += to_string(ans[i]);
  }
  cout << x << endl;
  return 0;
}
