#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  bool pos = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s - 1] != -1 and num[s - 1] != c) pos = false;
    num[s - 1] = c;
  }
  if (!pos or num[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (num[i] == -1)
        cout << 1;
      else
        cout << num[i];
      continue;
    }
    cout << (num[i] == -1 ? 0 : num[i]);
  }
  cout << endl;
  return 0;
}
