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