#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc(M);
  for (int i = 0; i < M; i++) {
    cin >> sc.at(i).first >> sc.at(i).second;
  }
  sort(sc.begin(), sc.end());
  if (sc.at(0).first == 1 && sc.at(0).second == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (N == 1) {
    int ans = -1;
    for (int i = 0; i < M; i++) {
      if (sc.at(i).first > 1) {
        cout << -1 << endl;
        return 0;
      } else {
        if (ans == -1) {
          ans = sc.at(i).second;
        } else {
          if (sc.at(i).second == ans) {
            continue;
          } else {
            cout << -1 << endl;
          }
        }
      }
    }
    cout << ans << endl;
  } else if (N == 2) {
    int ans_1 = -1;
    int ans_2 = -1;
    for (int i = 0; i < M; i++) {
      if (sc.at(i).first > 2) {
        cout << -1 << endl;
        return 0;
      } else {
        if (sc.at(i).first == 1) {
          if (ans_1 == -1) {
            ans_1 = sc.at(i).second;
          } else {
            if (sc.at(i).second == ans_1) {
              continue;
            } else {
              cout << -1 << endl;
              return 0;
            }
          }
        } else {
          if (ans_2 == -1) {
            ans_2 = sc.at(i).second;
          } else {
            if (sc.at(i).second == ans_2) {
              continue;
            } else {
              cout << -1 << endl;
              return 0;
            }
          }
        }
      }
    }
    int ans = 0;
    if (ans_2 != -1) {
      ans = ans_2;
    }
    if (ans_1 == -1) {
      ans += 10;
    } else {
      ans += ans_1 * 10;
    }
    cout << ans << endl;
  } else if (N == 3) {
    int ans_1 = -1;
    int ans_2 = -1;
    int ans_3 = -1;
    for (int i = 0; i < M; i++) {
      if (sc.at(i).first == 1) {
        if (ans_1 == -1) {
          ans_1 = sc.at(i).second;
        } else {
          if (sc.at(i).second == ans_1) {
            continue;
          } else {
            cout << -1 << endl;
            return 0;
          }
        }
      } else if (sc.at(i).first == 2) {
        if (ans_2 == -1) {
          ans_2 = sc.at(i).second;
        } else {
          if (sc.at(i).second == ans_2) {
            continue;
          } else {
            cout << -1 << endl;
            return 0;
          }
        }
      } else {
        if (ans_3 == -1) {
          ans_3 = sc.at(i).second;
        } else {
          if (sc.at(i).second == ans_3) {
            continue;
          } else {
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
    int ans = 0;
    if (ans_3 != -1) {
      ans = ans_3;
    }
    if (ans_2 != -1) {
      ans += ans_2 * 10;
    }
    if (ans_1 != -1) {
      ans += ans_1 * 100;
    } else {
      ans += 100;
    }
    cout << ans << endl;
  }
}
