#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n == 1) {
    if (m == 0)
      cout << 0 << endl;
    else {
      map<int, int> data;
      data[1] = -1;
      bool ans = true;
      for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        if (s == 1) {
          if (i == 0)
            data[s] = c;
          else {
            if (c != data[s]) {
              ans = false;
            }
          }
        }
        ans = false;
      }
      if (ans)
        cout << data[1] << endl;
      else
        cout << "-1" << endl;
    }
  }
  if (n == 2) {
    if (m == 0)
      cout << 10 << endl;
    else {
      map<int, int> data;
      data[1] = -1;
      data[2] = -1;
      bool num1 = true;
      bool num2 = true;
      bool ans = true;
      for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        if (s == 1) {
          if (num1) {
            data[1] = c;
            num1 = false;
          } else {
            if (c != data[1]) {
              ans = false;
            }
          }
        }
        if (s == 2) {
          if (num2) {
            data[2] = c;
            num2 = false;
          } else {
            if (c != data[2]) {
              ans = false;
            }
          }
        }
      }
      if (data[1] == 0) ans = false;
      if (!ans) cout << "-1" << endl;
      if (ans) {
        if (data[1] == -1) data[1] = 1;
        if (data[2] == -1) data[2] = 0;
        cout << data[1] * 10 + data[2] << endl;
      }
    }
  }
  if (n == 3) {
    if (m == 0)
      cout << 100 << endl;
    else {
      map<int, int> data;
      data[1] = -1;
      data[2] = -1;
      data[3] = -1;
      bool num1 = true;
      bool num2 = true;
      bool num3 = true;
      bool ans = true;
      for (int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        if (s == 1) {
          if (num1) {
            data[1] = c;
            num1 = false;
          } else {
            if (c != data[1]) {
              ans = false;
            }
          }
        }
        if (s == 2) {
          if (num2) {
            data[2] = c;
            num2 = false;
          } else {
            if (c != data[2]) {
              ans = false;
            }
          }
        }
        if (s == 3) {
          if (num3) {
            data[3] = c;
            num3 = false;
          } else {
            if (c != data[3]) {
              ans = false;
            }
          }
        }
      }
      if (data[1] == 0) ans = false;
      if (!ans) cout << "-1" << endl;
      if (ans) {
        if (data[1] == -1) data[1] = 1;
        if (data[2] == -1) data[2] = 0;
        if (data[3] == -1) data[3] = 0;
        cout << data[1] * 100 + data[2] * 10 + data[3] << endl;
      }
    }
  }
  return 0;
}
