#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  vector<int> a(m, -1);
  for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
       i += 1 - 2 * ((0) > (m))) {
    int s, c;
    cin >> s >> c;
    v.push_back({s, c});
  }
  bool ans = true;
  for (__typeof(v.size()) i = (0) - ((0) > (v.size()));
       i != (v.size()) - ((0) > (v.size())); i += 1 - 2 * ((0) > (v.size()))) {
    int index = v[i].first - 1;
    int number = v[i].second;
    if (a[index] == -1)
      a[index] = number;
    else if (a[index] != number)
      ans = false;
  }
  if (n != 1 && a[0] == 0) ans = false;
  if (ans == false)
    cout << -1;
  else
    for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));
         i += 1 - 2 * ((0) > (m))) {
      if (a[i] == -1 && i == 0)
        cout << 1;
      else if (a[i] == -1 && i != 0)
        cout << 0;
      else
        cout << a[i];
    }
  return 0;
}
