#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, bool>> v(n);
  for (long long i = (1); i <= (m); i++) {
    int s, c;
    cin >> s >> c;
    if (v[s - 1].second) {
      if (v[s - 1].first != c) {
        cout << "-1" << endl;
        ;
        return (0);
      }
    } else {
      v[s - 1].first = c;
      v[s - 1].second = true;
    }
  }
  if (v[0].second && v[0].first == 0) {
    cout << "-1" << endl;
    ;
    return (0);
  } else {
    if (v[0].first == 0) {
      v[0].first = 1;
    }
  }
  for (long long i = (0); i <= (n - 1); i++) {
    cout << v[i].first;
  }
  cout << endl;
  return (0);
}
