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