#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> s(m), c(m);
  bool flag = true;
  vector<int> number(10, -1);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) {
      if (n != 1) flag = false;
    } else if (number[s[i]] != -1 && number[s[i]] != c[i])
      flag = false;
    number[s[i]] = c[i];
  }
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  int sum = 0;
  for (int i = 1; i < 10; i++) {
    if (number[i] == -1) continue;
    sum += number[i] * pow(10, n - i);
  }
  cout << sum << endl;
  return 0;
}
