#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vec;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    vec.push_back(make_pair(x, y));
  }
  vector<int> num(n, 0);
  vector<bool> v(n, false);
  int flag = 0;
  for (int i = 0; i < m; i++) {
    if (vec[i].first == 1 && vec[i].second == 0) {
      cout << -1 << endl;
      flag = 1;
      break;
    } else if (v[vec[i].first - 1] == false) {
      num[vec[i].first - 1] += vec[i].second;
      v[vec[i].first - 1] = true;
    } else if (v[vec[i].first - 1] == true) {
      if (num[vec[i].first - 1] != vec[i].second) {
        cout << -1 << endl;
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0) {
    if (num[0] == 0) {
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (num[i] != 0) {
          cout << num[i];
          cnt++;
        }
      }
      while (cnt < n) {
        cout << 0;
        cnt++;
      }
      cout << endl;
    } else
      for (int i = 0; i < n; i++) cout << num[i];
  }
  return 0;
}
