import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    a();
  }

  public static void a() {
    try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    a();
  }

  public static void a() {
    try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    }
  }
} Main public static void main(String[] args) {
    a();
  } main {
    a();
  } a() a String[] args args public static void a() {
    try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    }
  } a {
    try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    }
  } try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    } {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int[] a = new int[5]; a new int[5] 5 a[0] = Integer.parseInt(sc.next()) a[0] a 0 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc a[1] = Integer.parseInt(sc.next()) a[1] a 1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc a[2] = Integer.parseInt(sc.next()) a[2] a 2 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc a[3] = Integer.parseInt(sc.next()) a[3] a 3 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc a[4] = Integer.parseInt(sc.next()) a[4] a 4 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int count = 0; count 0 for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      } int b a {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      } {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      } if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        } b == 0 b 0 {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        } if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          } count == 4 count 4 {
            System.out.println(a[3] + 1);
          } System.out.println(a[3] + 1) System.out.println System.out System System.out a[3] + 1 a[3] a 3 1 {
            System.out.println(a[count + 1] - 1);
          } System.out.println(a[count + 1] - 1) System.out.println System.out System System.out a[count + 1] - 1 a[count + 1] a count + 1 count 1 1 count++ count public class Main {
  public static void main(String[] args) {
    a();
  }

  public static void a() {
    try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    }
  }
} public class Main {
  public static void main(String[] args) {
    a();
  }

  public static void a() {
    try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    }
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    a();
  }

  public static void a() {
    try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    }
  }
}