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