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