#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const int MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N, -1);
  bool valid = true;
  for (int i = (int)(0); i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    if (num[s - 1] != -1 && num[s - 1] != c || s == 1 && c == 0) {
      valid = false;
      break;
    }
    num[s - 1] = c;
  }
  if (!valid) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = (int)(0); i < (int)(N); i++) {
    if (num[i] == -1) {
      if (i == 0)
        num[i] = 1;
      else
        num[i] = 0;
    }
    ans += num[i] * pow(10, N - i - 1);
  }
  cout << ans << endl;
}
