#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
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] >> c[i];
  }
  bool f = true;
  for (int i = 0; i < m - 1; i++) {
    if (s[i] == 1 && c[i] == 0) f = false;
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) f = false;
    }
  }
  vector<int> ans(n);
  for (int i = 0; i < m; i++) {
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == 0) ans[0] = 1;
  if (f)
    for (int i = 0; i < m; i++) {
      cout << ans[i];
    }
  else {
    cout << "-1" << endl;
  }
}
