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