#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s, c;
  for (int i = 0; i < (int)(M); i++) {
    int x, y;
    cin >> x >> y;
    s.push_back(x);
    c.push_back(y);
  }
  int ret[3] = {-1, -1, -1};
  for (int i = 0; i < (int)(M); i++) {
    if (ret[s[i] - 1] != -1 && ret[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      ret[s[i] - 1] = c[i];
    }
  }
  if (ret[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else if (ret[0] == -1) {
    ret[0] = 1;
  }
  int ans = 0;
  for (int i = 0; i < (int)(N); i++) {
    ans *= 10;
    ans += ret[i] == -1 ? 0 : ret[i];
  }
  cout << ans << endl;
  return 0;
}
