#include <bits/stdc++.h>
using namespace std;
long long INF = INT_MAX;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  bool ok = true;
  vector<int> s(n);
  for (int tt = 0; tt < m; tt++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (m == 1 && a == 0 && b == 0) {
      cout << "0\n";
      return 0;
    }
    if ((s[a] != 0 && s[a] != b) || (a == 0 && b == 0)) {
      ok = false;
    }
    s[a] = b;
  }
  if (!ok) {
    cout << "-1\n";
    return 0;
  }
  if (s[0] == 0) s[0] = 1;
  for (int i = 0; i < n; i++) cout << s[i];
  cout << "\n";
}
