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