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