#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main() {
  int N, M, s, c;
  cin >> N >> M;
  vector<int> ans(N, 10);
  for (int i = 0; i < M; ++i) {
    cin >> s >> c;
    if (ans[s - 1] != 10 && ans[s - 1] != c) {
      cout << "-1" << endl;
      return 0;
    }
    ans[s - 1] = c;
  }
  if (ans[0] == 0) {
    cout << "-1" << endl;
    return 0;
  } else if (ans[0] == 10)
    ans[0] = 1;
  for (auto a : ans) {
    if (a == 10) a = 0;
    cout << a;
  }
}
