#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
using P = pair<T, U>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int(i) = 0; (i) < (m); (i)++) {
    int ss, cc;
    cin >> ss >> cc;
    s[i] = ss - 1;
    c[i] = cc;
  }
  int designated[n];
  for (int(i) = 0; (i) < (n); (i)++) designated[i] = -1;
  int ans = 0;
  for (int(i) = 0; (i) < (m); (i)++) {
    if (designated[s[i]] != -1 && designated[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    designated[s[i]] = c[i];
  }
  if (designated[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    if (designated[i] == -1 && i == 0)
      cout << 1;
    else if (designated[i] == -1 && i > 0)
      cout << 0;
    else
      cout << designated[i];
  }
  cout << endl;
}
