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