#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m = 0;
  cin >> n >> m;
  vector<int> vec(2 * m);
  for (int i = 0; i < 2 * m; i++) {
    cin >> vec.at(i);
  }
  int ans = 0;
  bool ended = false;
  vector<int> tashita(10);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (vec.at(i * 2) == vec.at(j * 2) &&
          vec.at(i * 2 + 1) != vec.at(j * 2 + 1)) {
        ans = -1;
        ended = true;
      }
    }
  }
  if (!ended) {
    for (int i = 0; i < m; i++) {
      if (tashita.at(vec.at(i * 2) - 1) == 0) {
        ans += pow(10, n - vec.at(i * 2)) * vec.at(i * 2 + 1);
        tashita.at(vec.at(i * 2) - 1) = 1;
      }
    }
    int digit = 0;
    int a = ans;
    while (a != 0) {
      a /= 10;
      digit++;
    }
    if (digit != n) ans = -1;
  }
  cout << ans;
}
