#include <bits/stdc++.h>
using namespace std;
vector<int> v[10];
int main() {
  int n, m, s, c, mn = 100, i;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> s >> c;
    v[s - 1].push_back(c);
  }
  for (i = 0; i < n; i++) {
    sort(v[i].begin(), v[i].end());
  }
  if (v[0].size() != 0) {
    if (v[0][0] == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (1) {
    bool ok = true;
    for (i = 0; i < n; i++) {
      for (int j = 0; j < v[i].size(); j++) {
        if (v[i][0] != v[i][j]) {
          ok = false;
          break;
        }
      }
      if (!ok) break;
    }
    if (!ok)
      cout << "-1" << endl;
    else {
      for (i = 0; i < n; i++) {
        if (v[i].size() == 0) {
          if (i == 0)
            cout << 1;
          else
            cout << 0;
        } else
          cout << v[i][0];
      }
      cout << endl;
    }
  }
}
