#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[100], c[100];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  int ret[3];
  for (auto& it : ret) it = -1;
  for (int i = 0; i < m; ++i) {
    int keta = s[i];
    if (ret[m - keta] == -1 || ret[m - keta] == c[i])
      ret[m - keta] = c[i];
    else {
      cout << -1;
      return 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (ret[i] == -1) ret[i] = i == m - 1 ? 1 : 0;
  }
  int result = 0;
  int keta = 1;
  for (int i = 0; i < n; ++i) {
    result += ret[i] * keta;
    keta *= 10;
  }
  if (keta < result * 10)
    cout << result;
  else
    cout << -1;
}
