#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    sc[i] = make_pair(s, c);
  }
  bool ok = true;
  vector<int> ans(n);
  for (int i = 0; i < (m); ++i) {
    if (sc[i].first == 0) {
      if (sc[i].second == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
    for (int j = 0; j < (m); ++j) {
      if (sc[i].first == sc[j].first) {
        if (sc[i].second != sc[j].second) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
    ans[sc[i].first] = sc[i].second;
    if (sc[i].first == 0) {
      ok = false;
    }
  }
  if (ok) {
    ans[0] = 1;
  }
  for (int i = 0; i < (n); ++i) cout << ans[i];
}
