#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  for (int t = 1; t <= T; t++) {
    int n, m;
    cin >> n >> m;
    map<int, int> pos;
    map<int, bool> visited;
    bool yes = true;
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      if (visited[x]) {
        if (pos[x] != y) {
          yes = false;
        } else {
          pos[x] = y;
        }
      } else {
        pos[x] = y;
      }
      visited[x] = true;
    }
    if (m == 0) {
      pos[1] = 1;
    }
    if (!yes) {
      cout << "-1\n";
      return 0;
    }
    int output[n + 1];
    for (int i = 1; i <= n; i++) {
      output[i] = pos[i];
    }
    if (output[1] == 0 and output[2] == 0 and output[3] == 0) {
      cout << "-1\n";
      return 0;
    }
    if (output[1] + output[2] == 0) {
      cout << output[3] << "00\n";
      return 0;
    }
    if (output[1] > 0) {
      cout << output[1] << output[2] << output[3] << "\n";
      return 0;
    }
    if (output[2] > 0) {
      cout << output[2] << output[1] << output[3] << "\n";
      return 0;
    }
  }
}
