#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > sc(m);
  for (long long i = 0; i < (long long)(m); i++) {
    cin >> sc[i].first >> sc[i].second;
  }
  int digit[3] = {-1, -1, -1};
  for (long long i = 0; i < (long long)(m); i++) {
    if (digit[sc[i].first - 1] == -1) {
      digit[sc[i].first - 1] = sc[i].second;
    } else if (digit[sc[i].first - 1] != sc[i].second) {
      cout << "-1";
      return 0;
    }
  }
  if (n == 1) {
    if (digit[0] == 0) {
      cout << "-1";
      return 0;
    } else if (digit[0] == -1) {
      cout << "0";
      return 0;
    } else {
      cout << digit[0];
      return 0;
    }
  } else if (n == 2) {
    if (digit[0] == 0) {
      cout << "-1";
      return 0;
    } else if (digit[0] == -1) {
      digit[0] = 1;
    }
    if (digit[1] == -1) digit[1] = 0;
    cout << digit[0] * 10 + digit[1];
    return 0;
  } else {
    if (digit[0] == 0) {
      cout << "-1";
      return 0;
    } else if (digit[0] == -1) {
      digit[0] = 1;
    }
    if (digit[1] == -1) {
      digit[1] = 0;
    }
    if (digit[2] == -1) {
      digit[2] = 0;
    }
    cout << digit[0] * 100 + digit[1] * 10 + digit[2];
    return 0;
  }
}
