#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> m;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (m.count(s) == 1 && m[s] != c) {
      cout << "-1" << endl;
      return 0;
    } else {
      m.emplace(s, c);
    }
  }
  string ans = "";
  for (int i = 1; i <= N; i++) {
    ostringstream ss;
    if (m.count(i) == 1) {
      ss << m[i];
    } else {
      ss << 0;
    }
    ans = ans + ss.str();
  }
  if (ans.size() > 1) {
    if (ans[0] == '0') {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << ans << endl;
}
