#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(int argc, char const *argv[]) {
  unsigned N, M;
  cin >> N >> M;
  vector<int> ss(M);
  vector<int> cs(M);
  vector<int> num(N, -1);
  for (int i = (int)(0); i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    ss[i] = s;
    cs[i] = c;
  }
  for (int i = (int)(0); i < (int)(M); i++) {
    int s = ss[i] - 1;
    int c = cs[i];
    if (num[s] == -1) {
      num[s] = c;
    } else if (num[s] != c) {
      cout << -1 << endl;
      return 0;
    } else {
    }
  }
  int ans = 0;
  bool head = false;
  for (int j = (int)(0); j < (int)(N); j++) {
    ans *= 10;
    if (!head) {
      if (num[j] == 0) {
        cout << -1 << endl;
        return 0;
      }
      head = true;
    }
    if (num[j] == -1) {
      num[j] = 0;
    }
    ans += num[j];
  }
  cout << ans << endl;
  return 0;
}
